home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / gnu / gas / gassrc04.zoo / m68k.c < prev    next >
C/C++ Source or Header  |  1993-03-02  |  81KB  |  3,561 lines

  1. /* m68k.c  All the m68020 specific stuff in one convenient, huge,
  2.    slow to compile, easy to find file.
  3.    Copyright (C) 1987 Free Software Foundation, Inc.
  4.  
  5. This file is part of GAS, the GNU Assembler.
  6.  
  7. GAS is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 1, or (at your option)
  10. any later version.
  11.  
  12. GAS is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with GAS; see the file COPYING.  If not, write to
  19. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. #include <ctype.h>
  22.  
  23. #include "m68k-opcode.h"
  24. #include "as.h"
  25. #include "obstack.h"
  26. #include "frags.h"
  27. #include "struc-symbol.h"
  28. #include "flonum.h"
  29. #include "expr.h"
  30. #include "hash.h"
  31. #include "md.h"
  32. #include "m68k.h"
  33.  
  34. #ifdef M_SUN
  35. /* This variable contains the value to write out at the beginning of
  36.    the a.out file.  The 2<<16 means that this is a 68020 file instead
  37.    of an old-style 68000 file */
  38.  
  39. long omagic = 2<<16|OMAGIC;    /* Magic byte for header file */
  40. #else
  41. long omagic = OMAGIC;
  42. #endif
  43.  
  44.  
  45. /* This array holds the chars that always start a comment.  If the
  46.    pre-processor is disabled, these aren't very useful */
  47. const char comment_chars[] = "|";
  48.  
  49. /* This array holds the chars that only start a comment at the beginning of
  50.    a line.  If the line seems to have the form '# 123 filename'
  51.    .line and .file directives will appear in the pre-processed output */
  52. /* Note that input_file.c hand checks for '#' at the beginning of the
  53.    first line of the input file.  This is because the compiler outputs
  54.    #NO_APP at the beginning of its output. */
  55. /* Also note that '/*' will always start a comment */
  56. const char line_comment_chars[] = "#";
  57.  
  58. /* Chars that can be used to separate mant from exp in floating point nums */
  59. const char EXP_CHARS[] = "eE";
  60.  
  61. /* Chars that mean this number is a floating point constant */
  62. /* As in 0f12.456 */
  63. /* or    0d1.2345e12 */
  64.  
  65. const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
  66.  
  67. /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
  68.    changed in read.c .  Ideally it shouldn't have to know about it at all,
  69.    but nothing is ideal around here.
  70.  */
  71.  
  72. void fix_new();
  73. void install_operand();
  74. void install_gen_operand();
  75.  
  76. /* Its an arbitrary name:  This means I don't approve of it */
  77. /* See flames below */
  78. struct obstack robyn;
  79.  
  80. #define TAB(x,y)    (((x)<<2)+(y))
  81. #define TABTYPE(xy)     ((xy) >> 2)
  82. #define BYTE        0
  83. #define SHORT        1
  84. #define LONG        2
  85. #define SZ_UNDEF    3
  86.  
  87. #define BRANCH        1
  88. #define FBRANCH        2
  89. #define PCREL        3
  90. #define BCC68000        4
  91. #define DBCC            5
  92. #define PCLEA        6
  93.  
  94. /* BCC68000 is for patching in an extra jmp instruction for long offsets
  95.    on the 68000.  The 68000 doesn't support long branches with branchs */
  96.  
  97. /* This table desribes how you change sizes for the various types of variable
  98.    size expressions.  This version only supports two kinds. */
  99.  
  100. /* Note that calls to frag_var need to specify the maximum expansion needed */
  101. /* This is currently 10 bytes for DBCC */
  102.  
  103. /* The fields are:
  104.     How far Forward this mode will reach:
  105.     How far Backward this mode will reach:
  106.     How many bytes this mode will add to the size of the frag
  107.     Which mode to go to if the offset won't fit in this one
  108.  */
  109. const relax_typeS
  110. md_relax_table[] = {
  111. { 1,        1,        0,    0 },    /* First entries aren't used */
  112. { 1,        1,        0,    0 },    /* For no good reason except */
  113. { 1,        1,        0,    0 },    /* that the VAX doesn't either */
  114. { 1,        1,        0,    0 },
  115.  
  116. { (127),    (-128),        0,    TAB(BRANCH,SHORT)},
  117. { (32767),    (-32768),    2,    TAB(BRANCH,LONG) },
  118. { 0,        0,        4,    0 },
  119. { 1,        1,        0,    0 },
  120.  
  121. { 1,        1,        0,    0 },    /* FBRANCH doesn't come BYTE */
  122. { (32767),    (-32768),    2,    TAB(FBRANCH,LONG)},
  123. { 0,        0,        4,    0 },
  124. { 1,        1,        0,    0 },
  125.  
  126. { 1,        1,        0,    0 },    /* PCREL doesn't come BYTE */
  127. { (32767),    (-32768),    2,    TAB(PCREL,LONG)},
  128. { 0,        0,        4,    0 },
  129. { 1,        1,        0,    0 },
  130.  
  131. { (127),    (-128),        0,    TAB(BCC68000,SHORT)},
  132. { (32767),    (-32768),    2,    TAB(BCC68000,LONG) },
  133. { 0,        0,        6,    0 },    /* jmp long space */
  134. { 1,        1,        0,    0 },
  135.  
  136. { 1,        1,        0,    0 },    /* DBCC doesn't come BYTE */
  137. { (32767),    (-32768),    2,    TAB(DBCC,LONG) },
  138. { 0,        0,        10,    0 },    /* bra/jmp long space */
  139. { 1,        1,        0,    0 },
  140.  
  141. { 1,        1,        0,    0 },    /* PCLEA doesn't come BYTE */
  142. { 32767,    -32768,        2,    TAB(PCLEA,LONG) },
  143. { 0,        0,        6,    0 },
  144. { 1,        1,        0,    0 },
  145.  
  146. };
  147.  
  148. void    s_data1(),    s_data2(),    s_even(),    s_space();
  149. void    s_proc(),    float_cons();
  150.  
  151. /* These are the machine dependent pseudo-ops.  These are included so
  152.    the assembler can work on the output from the SUN C compiler, which
  153.    generates these.
  154.  */
  155.  
  156. /* This table describes all the machine specific pseudo-ops the assembler
  157.    has to support.  The fields are:
  158.        pseudo-op name without dot
  159.       function to call to execute this pseudo-op
  160.       Integer arg to pass to the function
  161.  */
  162. const pseudo_typeS md_pseudo_table[] = {
  163.     { "data1",    s_data1,    0    },
  164.     { "data2",    s_data2,    0    },
  165.     { "even",    s_even,        0    },
  166.     { "skip",    s_space,    0    },
  167.     { "proc",    s_proc,        0    },
  168.     { 0,        0,        0    }
  169. };
  170.  
  171.  
  172. /* #define isbyte(x)    ((x)>=-128 && (x)<=127) */
  173. /* #define isword(x)    ((x)>=-32768 && (x)<=32767) */
  174.  
  175. #define issbyte(x)    ((x)>=-128 && (x)<=127)
  176. #define isubyte(x)    ((x)>=0 && (x)<=255)
  177. #define issword(x)    ((x)>=-32768 && (x)<=32767)
  178. #define isuword(x)    ((x)>=0 && (x)<=65535)
  179.  
  180. #define isbyte(x)    ((x)>=-128 && (x)<=255)
  181. #define isword(x)    ((x)>=-32768 && (x)<=65535)
  182. #define islong(x)    (1)
  183.  
  184. extern char *input_line_pointer;
  185.  
  186. /* Operands we can parse:  (And associated modes)
  187.  
  188. numb:    8 bit num
  189. numw:    16 bit num
  190. numl:    32 bit num
  191. dreg:    data reg 0-7
  192. reg:    address or data register
  193. areg:    address register
  194. apc:    address register, PC, ZPC or empty string
  195. num:    16 or 32 bit num
  196. num2:    like num
  197. sz:    w or l        if omitted, l assumed
  198. scale:    1 2 4 or 8    if omitted, 1 assumed
  199.  
  200. 7.4 IMMED #num                --> NUM
  201. 0.? DREG  dreg                --> dreg
  202. 1.? AREG  areg                --> areg
  203. 2.? AINDR areg@                --> *(areg)
  204. 3.? AINC  areg@+            --> *(areg++)
  205. 4.? ADEC  areg@-            --> *(--areg)
  206. 5.? AOFF  apc@(numw)            --> *(apc+numw)    -- empty string and ZPC not allowed here
  207. 6.? AINDX apc@(num,reg:sz:scale)    --> *(apc+num+reg*scale)
  208. 6.? AINDX apc@(reg:sz:scale)        --> same, with num=0
  209. 6.? APODX apc@(num)@(num2,reg:sz:scale)    --> *(*(apc+num)+num2+reg*scale)
  210. 6.? APODX apc@(num)@(reg:sz:scale)    --> same, with num2=0
  211. 6.? AMIND apc@(num)@(num2)        --> *(*(apc+num)+num2) (previous mode without an index reg)
  212. 6.? APRDX apc@(num,reg:sz:scale)@(num2)    --> *(*(apc+num+reg*scale)+num2)
  213. 6.? APRDX apc@(reg:sz:scale)@(num2)    --> same, with num=0
  214. 7.0 ABSL  num:sz            --> *(num)
  215.           num                --> *(num) (sz L assumed)
  216. *** MSCR  otherreg            --> Magic
  217. With -l option
  218. 5.? AOFF  apc@(num)            --> *(apc+num) -- empty string and ZPC not allowed here still
  219.  
  220. examples:
  221.     #foo    #0x35    #12
  222.     d2
  223.     a4
  224.     a3@
  225.     a5@+
  226.     a6@-
  227.     a2@(12)    pc@(14)
  228.     a1@(5,d2:w:1)    @(45,d6:l:4)
  229.     pc@(a2)        @(d4)
  230.     etc . . .
  231.  
  232.  
  233. #name@(numw)    -->turn into PC rel mode
  234. apc@(num8,reg:sz:scale)        --> *(apc+num8+reg*scale)
  235.  
  236. */
  237.  
  238. #define IMMED    1
  239. #define DREG    2
  240. #define AREG    3
  241. #define AINDR    4
  242. #define ADEC    5
  243. #define AINC    6
  244. #define AOFF    7
  245. #define AINDX    8
  246. #define APODX    9
  247. #define AMIND    10
  248. #define APRDX    11
  249. #define ABSL    12
  250. #define MSCR    13
  251. #define REGLST    14
  252.  
  253. #define FAIL    0
  254. #define OK    1
  255.  
  256. /* DATA and ADDR have to be contiguous, so that reg-DATA gives 0-7==data reg,
  257.    8-15==addr reg for operands that take both types */
  258. #define DATA    1        /*   1- 8 == data registers 0-7 */
  259. #define ADDR    (DATA+8)    /*   9-16 == address regs 0-7 */
  260. #define FPREG    (ADDR+8)    /*  17-24 Eight FP registers */
  261. #define COPNUM    (FPREG+8)    /*  25-32 Co-processor #1-#8 */
  262.  
  263. #define PC    (COPNUM+8)    /*  33 Program counter */
  264. #define ZPC    (PC+1)        /*  34 Hack for Program space, but 0 addressing */
  265. #define SR    (ZPC+1)        /*  35 Status Reg */
  266. #define CCR    (SR+1)        /*  36 Condition code Reg */
  267.  
  268. /* These have to be in order for the movec instruction to work. */
  269. #define USP    (CCR+1)        /*  37 User Stack Pointer */
  270. #define ISP    (USP+1)        /*  38 Interrupt stack pointer */
  271. #define SFC    (ISP+1)        /*  39 */
  272. #define DFC    (SFC+1)        /*  40 */
  273. #define CACR    (DFC+1)        /*  41 */
  274. #define VBR    (CACR+1)    /*  42 */
  275. #define CAAR    (VBR+1)        /*  43 */
  276. #define MSP    (CAAR+1)    /*  44 */
  277.  
  278. #define FPI    (MSP+1)        /* 45 */
  279. #define FPS    (FPI+1)        /* 46 */
  280. #define FPC    (FPS+1)        /* 47 */
  281. /*
  282.  * these defines should be in m68k.c but
  283.  * i put them here to keep all the m68851 stuff
  284.  * together -rab
  285.  * JF--Make sure these #s don't clash with the ones in m68k.c
  286.  * That would be BAD.
  287.  */
  288. #define TC    (FPC+1)        /* 48 */
  289. #define DRP    (TC+1)        /* 49 */
  290. #define SRP    (DRP+1)        /* 50 */
  291. #define CRP    (SRP+1)        /* 51 */
  292. #define CAL    (CRP+1)        /* 52 */
  293. #define VAL    (CAL+1)        /* 53 */
  294. #define SCC    (VAL+1)        /* 54 */
  295. #define AC    (SCC+1)        /* 55 */
  296. #define BAD    (AC+1)        /* 56,57,58,59, 60,61,62,63 */
  297. #define BAC    (BAD+8)        /* 64,65,66,67, 68,69,70,71 */
  298. #define PSR    (BAC+8)        /* 72 */
  299. #define PCSR    (PSR+1)        /* 73 */
  300.  
  301.  
  302. /* Note that COPNUM==processor #1 -- COPNUM+7==#8, which stores as 000 */
  303. /* I think. . .  */
  304.  
  305. #define    SP    ADDR+7
  306.  
  307. /* JF these tables here are for speed at the expense of size */
  308. /* You can replace them with the #if 0 versions if you really
  309.    need space and don't mind it running a bit slower */
  310.  
  311. static char mklower_table[256];
  312. #define mklower(c) (mklower_table[(unsigned char)(c)])
  313. static char notend_table[256];
  314. static char alt_notend_table[256];
  315. #define notend(s) ( !(notend_table[(unsigned char)(*s)] || (*s==':' &&\
  316.  alt_notend_table[(unsigned char)(s[1])])))
  317.  
  318. #if 0
  319. #define mklower(c)    (isupper(c) ? tolower(c) : c)
  320. #endif
  321.  
  322.  
  323. struct m68k_exp {
  324.     char    *e_beg;
  325.     char    *e_end;
  326.     expressionS e_exp;
  327.     short    e_siz;        /* 0== default 1==short/byte 2==word 3==long */
  328. };
  329.  
  330. /* Internal form of an operand.  */
  331. struct m68k_op {
  332.     char    *error;        /* Couldn't parse it */
  333.     int    mode;        /* What mode this instruction is in.  */
  334.     unsigned long int    reg;        /* Base register */
  335.     struct m68k_exp *con1;
  336.     int    ireg;        /* Index register */
  337.     int    isiz;        /* 0==unspec  1==byte(?)  2==short  3==long  */
  338.     int    imul;        /* Multipy ireg by this (1,2,4,or 8) */
  339.     struct    m68k_exp *con2;
  340. };
  341.  
  342. /* internal form of a 68020 instruction */
  343. struct m68_it {
  344.     char    *error;
  345.     char    *args;        /* list of opcode info */
  346.     int    numargs;
  347.  
  348.     int    numo;        /* Number of shorts in opcode */
  349.     short    opcode[11];
  350.  
  351.     struct m68k_op operands[6];
  352.  
  353.     int    nexp;        /* number of exprs in use */
  354.     struct m68k_exp exprs[4];
  355.  
  356.     int    nfrag;        /* Number of frags we have to produce */
  357.     struct {
  358.         int fragoff;    /* Where in the current opcode[] the frag ends */
  359.         symbolS *fadd;
  360.         long int foff;
  361.         int fragty;
  362.     } fragb[4];
  363.  
  364.     int    nrel;        /* Num of reloc strucs in use */
  365.     struct    {
  366.         int    n;
  367.         symbolS    *add,
  368.             *sub;
  369.         long int off;
  370.         char    wid;
  371.         char    pcrel;
  372.     } reloc[5];        /* Five is enough??? */
  373. };
  374.  
  375. struct m68_it the_ins;        /* the instruction being assembled */
  376.  
  377.  
  378. /* Macros for adding things to the m68_it struct */
  379.  
  380. #define addword(w)    the_ins.opcode[the_ins.numo++]=(w)
  381.  
  382. /* Like addword, but goes BEFORE general operands */
  383. #define insop(w)    {int z;\
  384.  for(z=the_ins.numo;z>opcode->m_codenum;--z)\
  385.    the_ins.opcode[z]=the_ins.opcode[z-1];\
  386.  for(z=0;z<the_ins.nrel;z++)\
  387.    the_ins.reloc[z].n+=2;\
  388.  for(z=0;z<the_ins.nfrag;z++)\
  389.    the_ins.fragb[z].fragoff+=1;\
  390.  the_ins.opcode[opcode->m_codenum]=w;\
  391.  the_ins.numo++;\
  392. }
  393.  
  394.  
  395. #define add_exp(beg,end) (\
  396.     the_ins.exprs[the_ins.nexp].e_beg=beg,\
  397.     the_ins.exprs[the_ins.nexp].e_end=end,\
  398.     &the_ins.exprs[the_ins.nexp++]\
  399. )
  400.  
  401.  
  402. /* The numo+1 kludge is so we can hit the low order byte of the prev word. Blecch*/
  403. #define add_fix(width,exp,pc_rel) {\
  404.     the_ins.reloc[the_ins.nrel].n= ((width)=='B') ? (the_ins.numo*2-1) : \
  405.         (((width)=='b') ? ((the_ins.numo-1)*2) : (the_ins.numo*2));\
  406.     the_ins.reloc[the_ins.nrel].add=adds((exp));\
  407.     the_ins.reloc[the_ins.nrel].sub=subs((exp));\
  408.     the_ins.reloc[the_ins.nrel].off=offs((exp));\
  409.     the_ins.reloc[the_ins.nrel].wid=width;\
  410.     the_ins.reloc[the_ins.nrel++].pcrel=pc_rel;\
  411. }
  412.  
  413. #define add_frag(add,off,type)  {\
  414.     the_ins.fragb[the_ins.nfrag].fragoff=the_ins.numo;\
  415.     the_ins.fragb[the_ins.nfrag].fadd=add;\
  416.     the_ins.fragb[the_ins.nfrag].foff=off;\
  417.     the_ins.fragb[the_ins.nfrag++].fragty=type;\
  418. }
  419.  
  420. #define isvar(exp)    ((exp) && (adds(exp) || subs(exp)))
  421.  
  422. #define seg(exp)    ((exp)->e_exp.X_seg)
  423. #define adds(exp)    ((exp)->e_exp.X_add_symbol)
  424. #define subs(exp)    ((exp)->e_exp.X_subtract_symbol)
  425. #define offs(exp)    ((exp)->e_exp.X_add_number)
  426.  
  427.  
  428. struct m68_incant {
  429.     char *m_operands;
  430.     unsigned long m_opcode;
  431.     short m_opnum;
  432.     short m_codenum;
  433.     struct m68_incant *m_next;
  434. };
  435.  
  436. #define getone(x)    ((((x)->m_opcode)>>16)&0xffff)
  437. #define gettwo(x)    (((x)->m_opcode)&0xffff)
  438.  
  439. /* JF modified this to handle cases where the first part of a symbol name
  440.    looks like a register */
  441.  
  442. int
  443. m68k_reg_parse(ccp)
  444. register char **ccp;
  445. {
  446.     register char c1,
  447.         c2,
  448.         c3,
  449.         c4;
  450.     register int n = 0,
  451.         ret = FAIL;
  452.  
  453.     c1=mklower(ccp[0][0]);
  454. #ifdef REGISTER_PREFIX
  455.     if(c1!=REGISTER_PREFIX)
  456.         return FAIL;
  457.     c1=mklower(ccp[0][1]);
  458.     c2=mklower(ccp[0][2]);
  459.     c3=mklower(ccp[0][3]);
  460.     c4=mklower(ccp[0][4]);
  461. #else
  462.     c2=mklower(ccp[0][1]);
  463.     c3=mklower(ccp[0][2]);
  464.     c4=mklower(ccp[0][3]);
  465. #endif
  466.     switch(c1) {
  467.     case 'a':
  468.         if(c2>='0' && c2<='7') {
  469.             n=2;
  470.             ret=ADDR+c2-'0';
  471.         }
  472. #ifdef m68851
  473.         else if (c2 == 'c') {
  474.             n = 2;
  475.             ret = AC;
  476.         }
  477. #endif
  478.         break;
  479. #ifdef m68851
  480.     case 'b':
  481.         if (c2 == 'a') {
  482.             if (c3 == 'd') {
  483.                 if (c4 >= '0' && c4 <= '7') {
  484.                     n = 4;
  485.                     ret = BAD + c4 - '0';
  486.                 }
  487.             }
  488.             if (c3 == 'c') {
  489.                 if (c4 >= '0' && c4 <= '7') {
  490.                     n = 4;
  491.                     ret = BAC + c4 - '0';
  492.                 }
  493.             }
  494.         }
  495.         break;
  496. #endif
  497.     case 'c':
  498. #ifdef m68851
  499.         if (c2 == 'a' && c3 == 'l') {
  500.             n = 3;
  501.             ret = CAL;
  502.         } else
  503. #endif
  504.             /* This supports both CCR and CC as the ccr reg. */
  505.         if(c2=='c' && c3=='r') {
  506.             n=3;
  507.             ret = CCR;
  508.         } else if(c2=='c') {
  509.             n=2;
  510.             ret = CCR;
  511.         } else if(c2=='a' && (c3=='a' || c3=='c') && c4=='r') {
  512.             n=4;
  513.             ret = c3=='a' ? CAAR : CACR;
  514.         }
  515. #ifdef m68851
  516.         else if (c2 == 'r' && c3 == 'p') {
  517.             n = 3;
  518.             ret = (CRP);
  519.         }
  520. #endif
  521.         break;
  522.     case 'd':
  523.         if(c2>='0' && c2<='7') {
  524.             n=2;
  525.             ret = DATA+c2-'0';
  526.         } else if(c2=='f' && c3=='c') {
  527.             n=3;
  528.             ret = DFC;
  529.         }
  530. #ifdef m68851
  531.         else if (c2 == 'r' && c3 == 'p') {
  532.             n = 3;
  533.             ret = (DRP);
  534.         }
  535. #endif
  536.         break;
  537.     case 'f':
  538.         if(c2=='p') {
  539.             if(c3>='0' && c3<='7') {
  540.                 n=3;
  541.                 ret = FPREG+c3-'0';
  542.                 if(c4==':')
  543.                     ccp[0][3]=',';
  544.             } else if(c3=='i') {
  545.                 n=3;
  546.                 ret = FPI;
  547.             } else if(c3=='s') {
  548.                 n= (c4 == 'r' ? 4 : 3);
  549.                 ret = FPS;
  550.             } else if(c3=='c') {
  551.                 n= (c4 == 'r' ? 4 : 3);
  552.                 ret = FPC;
  553.             }
  554.         }
  555.         break;
  556.     case 'i':
  557.         if(c2=='s' && c3=='p') {
  558.             n=3;
  559.             ret = ISP;
  560.         }
  561.         break;
  562.     case 'm':
  563.         if(c2=='s' && c3=='p') {
  564.             n=3;
  565.             ret = MSP;
  566.         }
  567.         break;
  568.     case 'p':
  569.         if(c2=='c') {
  570. #ifdef m68851
  571.             if(c3 == 's' && c4=='r') {
  572.                 n=4;
  573.                 ret = (PCSR);
  574.             } else
  575. #endif
  576.             {
  577.                 n=2;
  578.                 ret = PC;
  579.             }
  580.         }
  581. #ifdef m68851
  582.         else if (c2 == 's' && c3 == 'r') {
  583.             n = 3;
  584.             ret = (PSR);
  585.         }
  586. #endif
  587.         break;
  588.     case 's':
  589. #ifdef m68851
  590.         if (c2 == 'c' && c3 == 'c') {
  591.             n = 3;
  592.             ret = (SCC);
  593.         } else if (c2 == 'r' && c3 == 'p') {
  594.             n = 3;
  595.             ret = (SRP);
  596.         } else
  597. #endif
  598.         if(c2=='r') {
  599.             n=2;
  600.             ret = SR;
  601.         } else if(c2=='p') {
  602.             n=2;
  603.             ret = ADDR+7;
  604.         } else if(c2=='f' && c3=='c') {
  605.             n=3;
  606.             ret = SFC;
  607.         }
  608.         break;
  609. #ifdef m68851
  610.     case 't':
  611.         if(c2 == 'c') {
  612.             n=2;
  613.             ret=TC;
  614.         }
  615.         break;
  616. #endif
  617.     case 'u':
  618.         if(c2=='s' && c3=='p') {
  619.             n=3;
  620.             ret = USP;
  621.         }
  622.         break;
  623.     case 'v':
  624. #ifdef m68851
  625.         if (c2 == 'a' && c3 == 'l') {
  626.             n = 3;
  627.             ret = (VAL);
  628.         } else
  629. #endif
  630.         if(c2=='b' && c3=='r') {
  631.             n=3;
  632.             ret = VBR;
  633.         }
  634.         break;
  635.     case 'z':
  636.         if(c2=='p' && c3=='c') {
  637.             n=3;
  638.             ret = ZPC;
  639.         }
  640.         break;
  641.     default:
  642.         break;
  643.     }
  644.     if(n) {
  645. #ifdef REGISTER_PREFIX
  646.         n++;
  647. #endif
  648.         if(isalnum(ccp[0][n]) || ccp[0][n]=='_')
  649.             ret=FAIL;
  650.         else
  651.             ccp[0]+=n;
  652.     } else
  653.         ret = FAIL;
  654.     return ret;
  655. }
  656.  
  657. #define SKIP_WHITE()    { str++; if(*str==' ') str++;}
  658.  
  659. int
  660. m68k_ip_op(str,opP)
  661. char *str;
  662. register struct m68k_op *opP;
  663. {
  664.     char    *strend;
  665.     long    i;
  666.     char    *parse_index();
  667.  
  668.     if(*str==' ')
  669.         str++;
  670.         /* Find the end of the string */
  671.     if(!*str) {
  672.         /* Out of gas */
  673.         opP->error="Missing operand";
  674.         return FAIL;
  675.     }
  676.     for(strend=str;*strend;strend++)
  677.         ;
  678.     --strend;
  679.  
  680.         /* Guess what:  A constant.  Shar and enjoy */
  681.     if(*str=='#') {
  682.         str++;
  683.         opP->con1=add_exp(str,strend);
  684.         opP->mode=IMMED;
  685.         return OK;
  686.     }
  687.     i=m68k_reg_parse(&str);
  688.     if((i==FAIL || *str!='\0') && *str!='@') {
  689.         char *stmp;
  690.         char *index();
  691.  
  692.         if(i!=FAIL && (*str=='/' || *str=='-')) {
  693.             opP->mode=REGLST;
  694.             return get_regs(i,str,opP);
  695.         }
  696.         if(stmp=index(str,'@')) {
  697.             opP->con1=add_exp(str,stmp-1);
  698.             if(stmp==strend) {
  699.                 opP->mode=AINDX;
  700.                 return OK;
  701.             }
  702.             stmp++;
  703.             if(*stmp++!='(' || *strend--!=')') {
  704.                 opP->error="Malformed operand";
  705.                 return FAIL;
  706.             }
  707.             i=try_index(&stmp,opP);
  708.             opP->con2=add_exp(stmp,strend);
  709.             if(i==FAIL) opP->mode=AMIND;
  710.             else opP->mode=APODX;
  711.             return OK;
  712.         }
  713.         opP->mode=ABSL;
  714.         opP->con1=add_exp(str,strend);
  715.         return OK;
  716.     }
  717.     opP->reg=i;
  718.     if(*str=='\0') {
  719.         if(i>=DATA+0 && i<=DATA+7)
  720.             opP->mode=DREG;
  721.         else if(i>=ADDR+0 && i<=ADDR+7)
  722.             opP->mode=AREG;
  723.         else
  724.             opP->mode=MSCR;
  725.         return OK;
  726.     }
  727.     if((i<ADDR+0 || i>ADDR+7) && i!=PC && i!=ZPC && i!=FAIL) {    /* Can't indirect off non address regs */
  728.         opP->error="Invalid indirect register";
  729.         return FAIL;
  730.     }
  731.     if(*str!='@')
  732.         abort();
  733.     str++;
  734.     switch(*str) {
  735.     case '\0':
  736.         opP->mode=AINDR;
  737.         return OK;
  738.     case '-':
  739.         opP->mode=ADEC;
  740.         return OK;
  741.     case '+':
  742.         opP->mode=AINC;
  743.         return OK;
  744.     case '(':
  745.         str++;
  746.         break;
  747.     default:
  748.         opP->error="Junk after indirect";
  749.         return FAIL;
  750.     }
  751.         /* Some kind of indexing involved.  Lets find out how bad it is */
  752.     i=try_index(&str,opP);
  753.         /* Didn't start with an index reg, maybe its offset or offset,reg */
  754.     if(i==FAIL) {
  755.         char *beg_str;
  756.  
  757.         beg_str=str;
  758.         for(i=1;i;) {
  759.             switch(*str++) {
  760.             case '\0':
  761.                 opP->error="Missing )";
  762.                 return FAIL;
  763.             case ',': i=0; break;
  764.             case '(': i++; break;
  765.             case ')': --i; break;
  766.             }
  767.         }
  768.         /* if(str[-3]==':') {
  769.             int siz;
  770.  
  771.             switch(str[-2]) {
  772.             case 'b':
  773.             case 'B':
  774.                 siz=1;
  775.                 break;
  776.             case 'w':
  777.             case 'W':
  778.                 siz=2;
  779.                 break;
  780.             case 'l':
  781.             case 'L':
  782.                 siz=3;
  783.                 break;
  784.             default:
  785.                 opP->error="Specified size isn't :w or :l";
  786.                 return FAIL;
  787.             }
  788.             opP->con1=add_exp(beg_str,str-4);
  789.             opP->con1->e_siz=siz;
  790.         } else */
  791.             opP->con1=add_exp(beg_str,str-2);
  792.             /* Should be offset,reg */
  793.         if(str[-1]==',') {
  794.             i=try_index(&str,opP);
  795.             if(i==FAIL) {
  796.                 opP->error="Malformed index reg";
  797.                 return FAIL;
  798.             }
  799.         }
  800.     }
  801.         /* We've now got offset)   offset,reg)   or    reg) */
  802.  
  803.     if(*str=='\0') {
  804.         /* Th-the-thats all folks */
  805.         if(opP->reg==FAIL) opP->mode=AINDX;    /* Other form of indirect */
  806.         else if(opP->ireg==FAIL) opP->mode=AOFF;
  807.         else opP->mode=AINDX;
  808.         return OK;
  809.     }
  810.         /* Next thing had better be another @ */
  811.     if(*str!='@' || str[1]!='(') {
  812.         opP->error="junk after indirect";
  813.         return FAIL;
  814.     }
  815.     str+=2;
  816.     if(opP->ireg!=FAIL) {
  817.         opP->mode=APRDX;
  818.         i=try_index(&str,opP);
  819.         if(i!=FAIL) {
  820.             opP->error="Two index registers!  not allowed!";
  821.             return FAIL;
  822.         }
  823.     } else
  824.         i=try_index(&str,opP);
  825.     if(i==FAIL) {
  826.         char *beg_str;
  827.  
  828.         beg_str=str;
  829.         for(i=1;i;) {
  830.             switch(*str++) {
  831.             case '\0':
  832.                 opP->error="Missing )";
  833.                 return FAIL;
  834.             case ',': i=0; break;
  835.             case '(': i++; break;
  836.             case ')': --i; break;
  837.             }
  838.         }
  839.         opP->con2=add_exp(beg_str,str-2);
  840.         if(str[-1]==',') {
  841.             if(opP->ireg!=FAIL) {
  842.                 opP->error="Can't have two index regs";
  843.                 return FAIL;
  844.             }
  845.             i=try_index(&str,opP);
  846.             if(i==FAIL) {
  847.                 opP->error="malformed index reg";
  848.                 return FAIL;
  849.             }
  850.             opP->mode=APODX;
  851.         } else if(opP->ireg!=FAIL)
  852.             opP->mode=APRDX;
  853.         else
  854.             opP->mode=AMIND;
  855.     } else
  856.         opP->mode=APODX;
  857.     if(*str!='\0') {
  858.         opP->error="Junk after indirect";
  859.         return FAIL;
  860.     }
  861.     return OK;
  862. }
  863.  
  864. int
  865. try_index(s,opP)
  866. char **s;
  867. struct m68k_op *opP;
  868. {
  869.     register int    i;
  870.     char    *ss;
  871. #define SKIP_W()    { ss++; if(*ss==' ') ss++;}
  872.  
  873.     ss= *s;
  874.     /* SKIP_W(); */
  875.     i=m68k_reg_parse(&ss);
  876.     if(!(i>=DATA+0 && i<=ADDR+7)) {    /* if i is not DATA or ADDR reg */
  877.         *s=ss;
  878.         return FAIL;
  879.     }
  880.     opP->ireg=i;
  881.     /* SKIP_W(); */
  882.     if(*ss==')') {
  883.         opP->isiz=0;
  884.         opP->imul=1;
  885.         SKIP_W();
  886.         *s=ss;
  887.         return OK;
  888.     }
  889.     if(*ss!=':') {
  890.         opP->error="Missing : in index register";
  891.         *s=ss;
  892.         return FAIL;
  893.     }
  894.     SKIP_W();
  895.     switch(*ss) {
  896.     case 'w':
  897.     case 'W':
  898.         opP->isiz=2;
  899.         break;
  900.     case 'l':
  901.     case 'L':
  902.         opP->isiz=3;
  903.         break;
  904.     default:
  905.         opP->error="Index register size spec not :w or :l";
  906.         *s=ss;
  907.         return FAIL;
  908.     }
  909.     SKIP_W();
  910.     if(*ss==':') {
  911.         SKIP_W();
  912.         switch(*ss) {
  913.         case '1':
  914.         case '2':
  915.         case '4':
  916.         case '8':
  917.             opP->imul= *ss-'0';
  918.             break;
  919.         default:
  920.             opP->error="index multiplier not 1, 2, 4 or 8";
  921.             *s=ss;
  922.             return FAIL;
  923.         }
  924.         SKIP_W();
  925.     } else opP->imul=1;
  926.     if(*ss!=')') {
  927.         opP->error="Missing )";
  928.         *s=ss;
  929.         return FAIL;
  930.     }
  931.     SKIP_W();
  932.     *s=ss;
  933.     return OK;
  934. }
  935.  
  936. #ifdef TEST1    /* TEST1 tests m68k_ip_op(), which parses operands */
  937. main()
  938. {
  939.     char buf[128];
  940.     struct m68k_op thark;
  941.  
  942.     for(;;) {
  943.         if(!gets(buf))
  944.             break;
  945.         bzero(&thark,sizeof(thark));
  946.         if(!m68k_ip_op(buf,&thark)) printf("FAIL:");
  947.         if(thark.error)
  948.             printf("op1 error %s in %s\n",thark.error,buf);
  949.         printf("mode %d, reg %d, ",thark.mode,thark.reg);
  950.         if(thark.b_const)
  951.             printf("Constant: '%.*s',",1+thark.e_const-thark.b_const,thark.b_const);
  952.         printf("ireg %d, isiz %d, imul %d ",thark.ireg,thark.isiz,thark.imul);
  953.         if(thark.b_iadd)
  954.             printf("Iadd: '%.*s'",1+thark.e_iadd-thark.b_iadd,thark.b_iadd);
  955.         printf("\n");
  956.     }
  957.     exit(0);
  958. }
  959.  
  960. #endif
  961.  
  962.  
  963. static struct hash_control*   op_hash = NULL;    /* handle of the OPCODE hash table
  964.                    NULL means any use before m68_ip_begin()
  965.                    will crash */
  966.  
  967.  
  968. /*
  969.  *        m 6 8 _ i p ( )
  970.  *
  971.  * This converts a string into a 68k instruction.
  972.  * The string must be a bare single instruction in sun format
  973.  * with RMS-style 68020 indirects
  974.  *  (example:  )
  975.  *
  976.  * It provides some error messages: at most one fatal error message (which
  977.  * stops the scan) and at most one warning message for each operand.
  978.  * The 68k instruction is returned in exploded form, since we have no
  979.  * knowledge of how you parse (or evaluate) your expressions.
  980.  * We do however strip off and decode addressing modes and operation
  981.  * mnemonic.
  982.  *
  983.  * This function's value is a string. If it is not "" then an internal
  984.  * logic error was found: read this code to assign meaning to the string.
  985.  * No argument string should generate such an error string:
  986.  * it means a bug in our code, not in the user's text.
  987.  *
  988.  * You MUST have called m86_ip_begin() once and m86_ip_end() never before using
  989.  * this function.
  990.  */
  991.  
  992. /* JF this function no longer returns a useful value.  Sorry */
  993. void
  994. m68_ip (instring)
  995. char    *instring;
  996. {
  997.     register char *p;
  998.     register struct m68k_op *opP;
  999.     register struct m68_incant *opcode;
  1000.     register char *s;
  1001.     register int tmpreg,
  1002.         baseo,
  1003.         outro,
  1004.         nextword;
  1005.     int    siz1,
  1006.         siz2;
  1007.     char    c;
  1008.     int    losing;
  1009.     int    opsfound;
  1010.     char    *crack_operand();
  1011.     LITTLENUM_TYPE words[6];
  1012.     LITTLENUM_TYPE *wordp;
  1013.  
  1014.     if (*instring == ' ')
  1015.         instring++;            /* skip leading whitespace */
  1016.  
  1017.   /* Scan up to end of operation-code, which MUST end in end-of-string
  1018.      or exactly 1 space. */
  1019.     for (p = instring; *p != '\0'; p++)
  1020.         if (*p == ' ')
  1021.             break;
  1022.  
  1023.  
  1024.     if (p == instring) {
  1025.         the_ins.error = "No operator";
  1026.         the_ins.opcode[0] = NULL;
  1027.         /* the_ins.numo=1; */
  1028.         return;
  1029.     }
  1030.  
  1031.   /* p now points to the end of the opcode name, probably whitespace.
  1032.      make sure the name is null terminated by clobbering the whitespace,
  1033.      look it up in the hash table, then fix it back. */   
  1034.     c = *p;
  1035.     *p = '\0';
  1036.     opcode = (struct m68_incant *)hash_find (op_hash, instring);
  1037.     *p = c;
  1038.  
  1039.     if (opcode == NULL) {
  1040.         the_ins.error = "Unknown operator";
  1041.         the_ins.opcode[0] = NULL;
  1042.         /* the_ins.numo=1; */
  1043.         return;
  1044.     }
  1045.  
  1046.   /* found a legitimate opcode, start matching operands */
  1047.     for(opP= &the_ins.operands[0];*p;opP++) {
  1048.         p = crack_operand (p, opP);
  1049.         if(opP->error) {
  1050.             the_ins.error=opP->error;
  1051.             return;
  1052.         }
  1053.     }
  1054.  
  1055.     opsfound=opP- &the_ins.operands[0];
  1056.     /* This ugly hack is to support the floating pt opcodes in their standard form */
  1057.     /* Essentially, we fake a first enty of type COP#1 */
  1058.     if(opcode->m_operands[0]=='I') {
  1059.         int    n;
  1060.  
  1061.         for(n=opsfound;n>0;--n)
  1062.             the_ins.operands[n]=the_ins.operands[n-1];
  1063.  
  1064.         /* bcopy((char *)(&the_ins.operands[0]),(char *)(&the_ins.operands[1]),opsfound*sizeof(the_ins.operands[0])); */
  1065.         bzero((char *)(&the_ins.operands[0]),sizeof(the_ins.operands[0]));
  1066.         the_ins.operands[0].mode=MSCR;
  1067.         the_ins.operands[0].reg=COPNUM;        /* COP #1 */
  1068.         opsfound++;
  1069.     }
  1070.         /* We've got the operands.  Find an opcode that'll
  1071.            accept them */
  1072.     for(losing=0;;) {
  1073.         if(opsfound!=opcode->m_opnum)
  1074.             losing++;
  1075.         else for(s=opcode->m_operands,opP= &the_ins.operands[0];*s && !losing;s+=2,opP++) {
  1076.                 /* Warning: this switch is huge! */
  1077.                 /* I've tried to organize the cases into  this order:
  1078.                    non-alpha first, then alpha by letter.  lower-case goes directly
  1079.                    before uppercase counterpart. */
  1080.                 /* Code with multiple case ...: gets sorted by the lowest case ...
  1081.                    it belongs to.  I hope this makes sense. */
  1082.             switch(*s) {
  1083.             case '!':
  1084.                 if(opP->mode==MSCR || opP->mode==IMMED ||
  1085.  opP->mode==DREG || opP->mode==AREG || opP->mode==AINC || opP->mode==ADEC || opP->mode==REGLST)
  1086.                     losing++;
  1087.                 break;
  1088.  
  1089.             case '#':
  1090.                 if(opP->mode!=IMMED)
  1091.                     losing++;
  1092.                 else {
  1093.                     long t;
  1094.  
  1095.                     t=get_num(opP->con1,80);
  1096.                     if(s[1]=='b' && !isbyte(t))
  1097.                         losing++;
  1098.                     else if(s[1]=='w' && !isword(t))
  1099.                         losing++;
  1100.                 }
  1101.                 break;
  1102.  
  1103.             case '^':
  1104.             case 'T':
  1105.                 if(opP->mode!=IMMED)
  1106.                     losing++;
  1107.                 break;
  1108.  
  1109.             case '$':
  1110.                 if(opP->mode==MSCR || opP->mode==AREG ||
  1111.  opP->mode==IMMED || opP->reg==PC || opP->reg==ZPC || opP->mode==REGLST)
  1112.                     losing++;
  1113.                 break;
  1114.  
  1115.             case '%':
  1116.                 if(opP->mode==MSCR || opP->reg==PC ||
  1117.  opP->reg==ZPC || opP->mode==REGLST)
  1118.                     losing++;
  1119.                 break;
  1120.  
  1121.  
  1122.             case '&':
  1123.                 if(opP->mode==MSCR || opP->mode==DREG ||
  1124.  opP->mode==AREG || opP->mode==IMMED || opP->reg==PC || opP->reg==ZPC ||
  1125.  opP->mode==AINC || opP->mode==ADEC || opP->mode==REGLST)
  1126.                     losing++;
  1127.                 break;
  1128.  
  1129.             case '*':
  1130.                 if(opP->mode==MSCR || opP->mode==REGLST)
  1131.                     losing++;
  1132.                 break;
  1133.  
  1134.             case '+':
  1135.                 if(opP->mode!=AINC)
  1136.                     losing++;
  1137.                 break;
  1138.  
  1139.             case '-':
  1140.                 if(opP->mode!=ADEC)
  1141.                     losing++;
  1142.                 break;
  1143.  
  1144.             case '/':
  1145.                 if(opP->mode==MSCR || opP->mode==AREG ||
  1146.  opP->mode==AINC || opP->mode==ADEC || opP->mode==IMMED || opP->mode==REGLST)
  1147.                     losing++;
  1148.                 break;
  1149.  
  1150.             case ';':
  1151.                 if(opP->mode==MSCR || opP->mode==AREG || opP->mode==REGLST)
  1152.                     losing++;
  1153.                 break;
  1154.  
  1155.             case '?':
  1156.                 if(opP->mode==MSCR || opP->mode==AREG ||
  1157.  opP->mode==AINC || opP->mode==ADEC || opP->mode==IMMED || opP->reg==PC ||
  1158.  opP->reg==ZPC || opP->mode==REGLST)
  1159.                     losing++;
  1160.                 break;
  1161.  
  1162.             case '@':
  1163.                 if(opP->mode==MSCR || opP->mode==AREG ||
  1164.  opP->mode==IMMED || opP->mode==REGLST)
  1165.                     losing++;
  1166.                 break;
  1167.  
  1168.             case '~':        /* For now! (JF FOO is this right?) */
  1169.                 if(opP->mode==MSCR || opP->mode==DREG ||
  1170.  opP->mode==AREG || opP->mode==IMMED || opP->reg==PC || opP->reg==ZPC || opP->mode==REGLST)
  1171.                     losing++;
  1172.                 break;
  1173.  
  1174.             case 'A':
  1175.                 if(opP->mode!=AREG)
  1176.                     losing++;
  1177.                 break;
  1178.  
  1179.             case 'B':    /* FOO */
  1180.                 if(opP->mode!=ABSL)
  1181.                     losing++;
  1182.                 break;
  1183.  
  1184.             case 'C':
  1185.                 if(opP->mode!=MSCR || opP->reg!=CCR)
  1186.                     losing++;
  1187.                 break;
  1188.  
  1189.             case 'd':    /* FOO This mode is a KLUDGE!! */
  1190.                 if(opP->mode!=AOFF && (opP->mode!=ABSL ||
  1191.  opP->con1->e_beg[0]!='(' || opP->con1->e_end[0]!=')'))
  1192.                     losing++;
  1193.                 break;
  1194.  
  1195.             case 'D':
  1196.                 if(opP->mode!=DREG)
  1197.                     losing++;
  1198.                 break;
  1199.  
  1200.             case 'F':
  1201.                 if(opP->mode!=MSCR || opP->reg<(FPREG+0) || opP->reg>(FPREG+7))
  1202.                     losing++;
  1203.                 break;
  1204.  
  1205.             case 'I':
  1206.                 if(opP->mode!=MSCR || opP->reg<COPNUM ||
  1207.  opP->reg>=COPNUM+7)
  1208.                     losing++;
  1209.                 break;
  1210.  
  1211.             case 'J':
  1212.                 if(opP->mode!=MSCR || opP->reg<USP || opP->reg>MSP)
  1213.                     losing++;
  1214.                 break;
  1215.  
  1216.             case 'k':
  1217.                 if(opP->mode!=IMMED)
  1218.                     losing++;
  1219.                 break;
  1220.  
  1221.             case 'l':
  1222.             case 'L':
  1223.                 if(opP->mode==DREG || opP->mode==AREG || opP->mode==FPREG) {
  1224.                     if(s[1]=='8')
  1225.                         losing++;
  1226.                     else {
  1227.                         opP->mode=REGLST;
  1228.                         opP->reg=1<<(opP->reg-DATA);
  1229.                     }
  1230.                 } else if(opP->mode!=REGLST) {
  1231.                     losing++;
  1232.                 } else if(s[1]=='8' && opP->reg&0x0FFffFF)
  1233.                     losing++;
  1234.                 else if(s[1]=='3' && opP->reg&0x7000000)
  1235.                     losing++;
  1236.                 break;
  1237.  
  1238.             case 'M':
  1239.                 if(opP->mode!=IMMED)
  1240.                     losing++;
  1241.                 else {
  1242.                     long t;
  1243.  
  1244.                     t=get_num(opP->con1,80);
  1245.                     if(!issbyte(t) || isvar(opP->con1))
  1246.                         losing++;
  1247.                 }
  1248.                 break;
  1249.  
  1250.             case 'O':
  1251.                 if(opP->mode!=DREG && opP->mode!=IMMED)
  1252.                     losing++;
  1253.                 break;
  1254.  
  1255.             case 'Q':
  1256.                 if(opP->mode!=IMMED)
  1257.                     losing++;
  1258.                 else {
  1259.                     long t;
  1260.  
  1261.                     t=get_num(opP->con1,80);
  1262.                     if (s[1]!='s') {
  1263.                         if(t<1 || t>8 || isvar(opP->con1))
  1264.                             losing++;
  1265.                     }
  1266.                     else {
  1267.                         if(t<0 || t>7 || isvar(opP->con1))
  1268.                             losing++;
  1269.                     }
  1270.                 }
  1271.                 break;
  1272.  
  1273.             case 'R':
  1274.                 if(opP->mode!=DREG && opP->mode!=AREG)
  1275.                     losing++;
  1276.                 break;
  1277.  
  1278.             case 's':
  1279.                 if(opP->mode!=MSCR || !(opP->reg==FPI || opP->reg==FPS || opP->reg==FPC))
  1280.                     losing++;
  1281.                 break;
  1282.  
  1283.             case 'S':
  1284.                 if(opP->mode!=MSCR || opP->reg!=SR)
  1285.                     losing++;
  1286.                 break;
  1287.  
  1288.             case 'U':
  1289.                 if(opP->mode!=MSCR || opP->reg!=USP)
  1290.                     losing++;
  1291.                 break;
  1292.  
  1293.             /* JF these are out of order.  We could put them
  1294.                in order if we were willing to put up with
  1295.                bunches of #ifdef m68851s in the code */
  1296. #ifdef m68851
  1297.             /* Memory addressing mode used by pflushr */
  1298.             case '|':
  1299.                 if(opP->mode==MSCR || opP->mode==DREG ||
  1300.  opP->mode==AREG || opP->mode==REGLST)
  1301.                     losing++;
  1302.                 break;
  1303.  
  1304.             case 'f':
  1305.                 if (opP->mode != MSCR || (opP->reg != SFC && opP->reg != DFC))
  1306.                     losing++;
  1307.                 break;
  1308.  
  1309.             case 'P':
  1310.                 if (opP->mode != MSCR || (opP->reg != TC && opP->reg != CAL &&
  1311.                     opP->reg != VAL && opP->reg != SCC && opP->reg != AC))
  1312.                     losing++;
  1313.                 break;
  1314.  
  1315.             case 'V':
  1316.                 if (opP->reg != VAL)
  1317.                     losing++;
  1318.                 break;
  1319.  
  1320.             case 'W':
  1321.                 if (opP->mode != MSCR || (opP->reg != DRP && opP->reg != SRP &&
  1322.                     opP->reg != CRP))
  1323.                     losing++;
  1324.                 break;
  1325.  
  1326.             case 'X':
  1327.                 if (opP->mode != MSCR ||
  1328.                     (!(opP->reg >= BAD && opP->reg <= BAD+7) &&
  1329.                      !(opP->reg >= BAC && opP->reg <= BAC+7)))
  1330.                     losing++;
  1331.                 break;
  1332.  
  1333.             case 'Y':
  1334.                 if (opP->reg != PSR)
  1335.                     losing++;
  1336.                 break;
  1337.  
  1338.             case 'Z':
  1339.                 if (opP->reg != PCSR)
  1340.                     losing++;
  1341.                 break;
  1342. #endif
  1343.             default:
  1344.                 as_fatal("Internal error:  Operand mode %c unknown",*s);
  1345.             }
  1346.         }
  1347.         if(!losing)
  1348.             break;
  1349.         opcode=opcode->m_next;
  1350.         if(!opcode) {        /* Fell off the end */
  1351.             the_ins.error="instruction/operands mismatch";
  1352.             return;
  1353.         }
  1354.         losing=0;
  1355.     }
  1356.     the_ins.args=opcode->m_operands;
  1357.     the_ins.numargs=opcode->m_opnum;
  1358.     the_ins.numo=opcode->m_codenum;
  1359.     the_ins.opcode[0]=getone(opcode);
  1360.     the_ins.opcode[1]=gettwo(opcode);
  1361.  
  1362.     for(s=the_ins.args,opP= &the_ins.operands[0];*s;s+=2,opP++) {
  1363.             /* This switch is a doozy.
  1364.                What the first step; its a big one! */
  1365.         switch(s[0]) {
  1366.  
  1367.         case '*':
  1368.         case '~':
  1369.         case '%':
  1370.         case ';':
  1371.         case '@':
  1372.         case '!':
  1373.         case '&':
  1374.         case '$':
  1375.         case '?':
  1376.         case '/':
  1377. #ifdef m68851
  1378.         case '|':
  1379. #endif
  1380.             switch(opP->mode) {
  1381.             case IMMED:
  1382.                 tmpreg=0x3c;    /* 7.4 */
  1383.                 if(index("bwl",s[1])) nextword=get_num(opP->con1,80);
  1384.                 else nextword=nextword=get_num(opP->con1,0);
  1385.                 if(isvar(opP->con1))
  1386.                     add_fix(s[1],opP->con1,0);
  1387.                 switch(s[1]) {
  1388.                 case 'b':
  1389.                     if(!isbyte(nextword))
  1390.                         opP->error="operand out of range";
  1391.                     addword(nextword);
  1392.                     baseo=0;
  1393.                     break;
  1394.                 case 'w':
  1395.                     if(!isword(nextword))
  1396.                         opP->error="operand out of range";
  1397.                     addword(nextword);
  1398.                     baseo=0;
  1399.                     break;
  1400.                 case 'l':
  1401.                     addword(nextword>>16);
  1402.                     addword(nextword);
  1403.                     baseo=0;
  1404.                     break;
  1405.  
  1406.                 case 'f':
  1407.                     baseo=2;
  1408.                     outro=8;
  1409.                     break;
  1410.                 case 'F':
  1411.                     baseo=4;
  1412.                     outro=11;
  1413.                     break;
  1414.                 case 'x':
  1415.                     baseo=6;
  1416.                     outro=15;
  1417.                     break;
  1418.                 case 'p':
  1419.                     baseo=6;
  1420.                     outro= -1;
  1421.                     break;
  1422.                 default:
  1423.                     as_fatal("Internal error:  Can't decode %c%c",*s,s[1]);
  1424.                 }
  1425.                 if(!baseo)
  1426.                     break;
  1427.  
  1428.                 /* We gotta put out some float */
  1429.                 if(seg(opP->con1)!=SEG_BIG) {
  1430.                     int_to_gen(nextword);
  1431.                     gen_to_words(words,baseo,(long int)outro);
  1432.                     for(wordp=words;baseo--;wordp++)
  1433.                         addword(*wordp);
  1434.                     break;
  1435.                 }        /* Its BIG */
  1436.                 if(offs(opP->con1)>0) {
  1437.                     as_warn("Bignum assumed to be binary bit-pattern");
  1438.                     if(offs(opP->con1)>baseo) {
  1439.                         as_warn("Bignum too big for %c format; truncated",s[1]);
  1440.                         offs(opP->con1)=baseo;
  1441.                     }
  1442.                     baseo-=offs(opP->con1);
  1443.                     for(wordp=generic_bignum+offs(opP->con1)-1;offs(opP->con1)--;--wordp)
  1444.                         addword(*wordp);
  1445.                     while(baseo--)
  1446.                         addword(0);
  1447.                     break;
  1448.                 }
  1449.                 gen_to_words(words,baseo,(long int)outro);
  1450.                 for(wordp=words;baseo--;wordp++)
  1451.                     addword(*wordp);
  1452.                 break;
  1453.             case DREG:
  1454.                 tmpreg=opP->reg-DATA; /* 0.dreg */
  1455.                 break;
  1456.             case AREG:
  1457.                 tmpreg=0x08+opP->reg-ADDR; /* 1.areg */
  1458.                 break;
  1459.             case AINDR:
  1460.                 tmpreg=0x10+opP->reg-ADDR; /* 2.areg */
  1461.                 break;
  1462.             case ADEC:
  1463.                 tmpreg=0x20+opP->reg-ADDR; /* 4.areg */
  1464.                 break;
  1465.             case AINC:
  1466.                 tmpreg=0x18+opP->reg-ADDR; /* 3.areg */
  1467.                 break;
  1468.             case AOFF:
  1469.  
  1470.                 nextword=get_num(opP->con1,80);
  1471.                 /* Force into index mode.  Hope this works */
  1472.  
  1473.                 /* We do the first bit for 32-bit displacements,
  1474.                    and the second bit for 16 bit ones.  It is
  1475.                    possible that we should make the default be
  1476.                    WORD instead of LONG, but I think that'd
  1477.                    break GCC, so we put up with a little
  1478.                    inefficiency for the sake of working output.
  1479.                  */
  1480.  
  1481.                 if(   !issword(nextword)
  1482.                    || (   isvar(opP->con1)
  1483.                        && (  (   opP->con1->e_siz==0
  1484.                           && flagseen['l']!=0)
  1485.                        || opP->con1->e_siz==3))) {
  1486.  
  1487.                     if(opP->reg==PC)
  1488.                         tmpreg=0x3B;    /* 7.3 */
  1489.                     else
  1490.                         tmpreg=0x30+opP->reg-ADDR;    /* 6.areg */
  1491.                     if(isvar(opP->con1)) {
  1492.                         if(opP->reg==PC &&
  1493.                            !subs(opP->con1)) {
  1494.                             add_frag(adds(opP->con1),
  1495.                              offs(opP->con1)+2,
  1496.                              TAB(PCLEA,SZ_UNDEF));
  1497.                             break;
  1498.                         } else {
  1499.                             addword(0x0170);
  1500.                             add_fix('l',opP->con1,0);
  1501.                         }
  1502.                     } else
  1503.                         addword(0x0170);
  1504.                     addword(nextword>>16);
  1505.                 } else {
  1506.                     if(opP->reg==PC)
  1507.                         tmpreg=0x3A; /* 7.2 */
  1508.                     else
  1509.                         tmpreg=0x28+opP->reg-ADDR; /* 5.areg */
  1510.  
  1511.                     if(isvar(opP->con1)) {
  1512.                         if(opP->reg==PC &&
  1513.                            !subs(opP->con1)) {
  1514.                             offs(opP->con1) += 2;
  1515.                             add_fix('w',opP->con1,1);
  1516.                         } else
  1517.                             add_fix('w',opP->con1,0);
  1518.                         }
  1519.                 }
  1520.                 addword(nextword);
  1521.                 break;
  1522.             case AINDX:
  1523.             case APODX:
  1524.             case AMIND:
  1525.             case APRDX:
  1526.                 nextword=0;
  1527.                 baseo=get_num(opP->con1,80);
  1528.                 outro=get_num(opP->con2,80);
  1529.                     /* Figure out the 'addressing mode' */
  1530.                     /* Also turn on the BASE_DISABLE bit, if needed */
  1531.                 if(opP->reg==PC || opP->reg==ZPC) {
  1532.                     tmpreg=0x3b; /* 7.3 */
  1533.                     if(opP->reg==ZPC)
  1534.                         nextword|=0x80;
  1535.                 } else if(opP->reg==FAIL) {
  1536.                     nextword|=0x80;
  1537.                     tmpreg=0x30;    /* 6.garbage */
  1538.                 } else tmpreg=0x30+opP->reg-ADDR; /* 6.areg */
  1539.  
  1540.                 siz1= (opP->con1) ? opP->con1->e_siz : 0;
  1541.                 siz2= (opP->con2) ? opP->con2->e_siz : 0;
  1542.  
  1543.                     /* Index register stuff */
  1544.                 if(opP->ireg>=DATA+0 && opP->ireg<=ADDR+7) {
  1545.                     nextword|=(opP->ireg-DATA)<<12;
  1546.  
  1547.                     if(opP->isiz==0 || opP->isiz==3)
  1548.                         nextword|=0x800;
  1549.                     switch(opP->imul) {
  1550.                     case 1: break;
  1551.                     case 2: nextword|=0x200; break;
  1552.                     case 4: nextword|=0x400; break;
  1553.                     case 8: nextword|=0x600; break;
  1554.                     default: abort();
  1555.                     }
  1556.                         /* IF its simple,
  1557.                            GET US OUT OF HERE! */
  1558.  
  1559.                         /* Must be INDEX, with an index
  1560.                            register.  Address register
  1561.                            cannot be ZERO-PC, and either
  1562.                            :b was forced, or we know
  1563.                            it will fit */
  1564.                     if(   opP->mode==AINDX
  1565.                        && opP->reg!=FAIL
  1566.                        && opP->reg!=ZPC
  1567.                        && (   siz1==1
  1568.                            || (   issbyte(baseo)
  1569.                            && !isvar(opP->con1)))) {
  1570.                         nextword +=baseo&0xff;
  1571.                         addword(nextword);
  1572.                         if(isvar(opP->con1))
  1573.                             if(opP->reg==PC &&
  1574.                                !subs(opP->con1)) {
  1575.                                 offs(opP->con1) += 2;
  1576.                                 add_fix('B',opP->con1,1);
  1577.                             } else
  1578.                                 add_fix('B',opP->con1,0);
  1579.                         break;
  1580.                     }
  1581.                 } else
  1582.                     nextword|=0x40;    /* No index reg */
  1583.  
  1584.                     /* It aint simple */
  1585.                 nextword|=0x100;
  1586.                     /* If the guy specified a width, we assume that
  1587.                        it is wide enough.  Maybe it isn't.  Ifso, we lose
  1588.                      */
  1589.                 switch(siz1) {
  1590.                 case 0:
  1591.                     if(isvar(opP->con1) || !issword(baseo)) {
  1592.                         siz1=3;
  1593.                         nextword|=0x30;
  1594.                     } else if(baseo==0)
  1595.                         nextword|=0x10;
  1596.                     else {    
  1597.                         nextword|=0x20;
  1598.                         siz1=2;
  1599.                     }
  1600.                     break;
  1601.                 case 1:
  1602.                     as_warn("Byte dispacement won't work.  Defaulting to :w");
  1603.                 case 2:
  1604.                     nextword|=0x20;
  1605.                     break;
  1606.                 case 3:
  1607.                     nextword|=0x30;
  1608.                     break;
  1609.                 }
  1610.  
  1611.                     /* Figure out innner displacement stuff */
  1612.                 if(opP->mode!=AINDX) {
  1613.                     switch(siz2) {
  1614.                     case 0:
  1615.                         if(isvar(opP->con2) || !issword(outro)) {
  1616.                             siz2=3;
  1617.                             nextword|=0x3;
  1618.                         } else if(outro==0)
  1619.                             nextword|=0x1;
  1620.                         else {    
  1621.                             nextword|=0x2;
  1622.                             siz2=2;
  1623.                         }
  1624.                         break;
  1625.                     case 1:
  1626.                         as_warn("Byte dispacement won't work.  Defaulting to :w");
  1627.                     case 2:
  1628.                         nextword|=0x2;
  1629.                         break;
  1630.                     case 3:
  1631.                         nextword|=0x3;
  1632.                         break;
  1633.                     }
  1634.                     if(opP->mode==APODX) nextword|=0x04;
  1635.                     else if(opP->mode==AMIND) nextword|=0x40;
  1636.                 }
  1637.                 addword(nextword);
  1638.  
  1639.                 if(isvar(opP->con1)) {
  1640.                     if((opP->reg==PC || opP->reg==ZPC) &&
  1641.                        !subs(opP->con1)) {
  1642.                         offs(opP->con1) += (siz1==3) ? 6 : 4;
  1643.                         add_fix(siz1==3 ? 'l' : 'w',opP->con1,1);
  1644.  
  1645.                     } else
  1646.                         add_fix(siz1==3 ? 'l' : 'w',opP->con1,0);
  1647.                 }
  1648.                 if(siz1==3)
  1649.                     addword(baseo>>16);
  1650.                 if(siz1)
  1651.                     addword(baseo);
  1652.  
  1653.                 if(isvar(opP->con2)) {
  1654.                     add_fix(siz2==3 ? 'l' : 'w',opP->con2,0);
  1655.                 }
  1656.                 if(siz2==3)
  1657.                     addword(outro>>16);
  1658.                 if(siz2)
  1659.                     addword(outro);
  1660.  
  1661.                 break;
  1662.  
  1663.             case ABSL:
  1664.                 nextword=get_num(opP->con1,80);
  1665.                 switch(opP->con1->e_siz) {
  1666.                 default:
  1667.                     as_warn("Unknown size for absolute reference");
  1668.                 case 0:
  1669.                     if(!isvar(opP->con1) && issword(offs(opP->con1))) {
  1670.                         tmpreg=0x38; /* 7.0 */
  1671.                         addword(nextword);
  1672.                         break;
  1673.                     }
  1674.                     /* Don't generate pc relative code
  1675.                        on 68010 and 68000 */
  1676.                     if(isvar(opP->con1) &&
  1677.                        !subs(opP->con1) &&
  1678.                        seg(opP->con1)==SEG_TEXT &&
  1679.                        now_seg==SEG_TEXT &&
  1680.                        flagseen['m']==0 &&
  1681.                         !index("~%&$?", s[0])) {
  1682.                         tmpreg=0x3A; /* 7.2 */
  1683.                         add_frag(adds(opP->con1),
  1684.                              offs(opP->con1),
  1685.                              TAB(PCREL,SZ_UNDEF));
  1686.                         break;
  1687.                     }
  1688.                 case 3:        /* Fall through into long */
  1689.                     if(isvar(opP->con1))
  1690.                         add_fix('l',opP->con1,0);
  1691.  
  1692.                     tmpreg=0x39;    /* 7.1 mode */
  1693.                     addword(nextword>>16);
  1694.                     addword(nextword);
  1695.                     break;
  1696.  
  1697.                 case 2:        /* Word */
  1698.                     if(isvar(opP->con1))
  1699.                         add_fix('w',opP->con1,0);
  1700.  
  1701.                     tmpreg=0x38;    /* 7.0 mode */
  1702.                     addword(nextword);
  1703.                     break;
  1704.                 }
  1705.                 break;
  1706.             case MSCR:
  1707.             default:
  1708.                 as_bad("unknown/incorrect operand");
  1709.                 /* abort(); */
  1710.             }
  1711.             install_gen_operand(s[1],tmpreg);
  1712.             break;
  1713.  
  1714.         case '#':
  1715.         case '^':
  1716.             switch(s[1]) {    /* JF: I hate floating point! */
  1717.             case 'j':
  1718.                 tmpreg=70;
  1719.                 break;
  1720.             case '8':
  1721.                 tmpreg=20;
  1722.                 break;
  1723.             case 'C':
  1724.                 tmpreg=50;
  1725.                 break;
  1726.             case '3':
  1727.             default:
  1728.                 tmpreg=80;
  1729.                 break;
  1730.             }
  1731.             tmpreg=get_num(opP->con1,tmpreg);
  1732.             if(isvar(opP->con1))
  1733.                 add_fix(s[1],opP->con1,0);
  1734.             switch(s[1]) {
  1735.             case 'b':    /* Danger:  These do no check for
  1736.                        certain types of overflow.
  1737.                        user beware! */
  1738.                 if(!isbyte(tmpreg))
  1739.                     opP->error="out of range";
  1740.                 insop(tmpreg);
  1741.                 if(isvar(opP->con1))
  1742.                     the_ins.reloc[the_ins.nrel-1].n=(opcode->m_codenum)*2;
  1743.                 break;
  1744.             case 'w':
  1745.                 if(!isword(tmpreg))
  1746.                     opP->error="out of range";
  1747.                 insop(tmpreg);
  1748.                 if(isvar(opP->con1))
  1749.                     the_ins.reloc[the_ins.nrel-1].n=(opcode->m_codenum)*2;
  1750.                 break;
  1751.             case 'l':
  1752.                 insop(tmpreg);        /* Because of the way insop works, we put these two out backwards */
  1753.                 insop(tmpreg>>16);
  1754.                 if(isvar(opP->con1))
  1755.                     the_ins.reloc[the_ins.nrel-1].n=(opcode->m_codenum)*2;
  1756.                 break;
  1757.             case '3':
  1758.                 tmpreg&=0xFF;
  1759.             case '8':
  1760.             case 'C':
  1761.                 install_operand(s[1],tmpreg);
  1762.                 break;
  1763.             default:
  1764.                 as_fatal("Internal error:  Unknown mode #%c",s[1]);
  1765.             }
  1766.             break;
  1767.  
  1768.         case '+':
  1769.         case '-':
  1770.         case 'A':
  1771.             install_operand(s[1],opP->reg-ADDR);
  1772.             break;
  1773.  
  1774.         case 'B':
  1775.             tmpreg=get_num(opP->con1,80);
  1776.             switch(s[1]) {
  1777.             case 'g':
  1778.                 if(opP->con1->e_siz) {    /* Deal with fixed size stuff by hand */
  1779.                     switch(opP->con1->e_siz) {
  1780.                     case 1:
  1781.                         add_fix('b',opP->con1,1);
  1782.                         break;
  1783.                     case 2:
  1784.                         add_fix('w',opP->con1,1);
  1785.                         addword(0);
  1786.                         break;
  1787.                     case 3:
  1788.                         add_fix('l',opP->con1,1);
  1789.                         addword(0);
  1790.                         addword(0);
  1791.                         break;
  1792.                     default:
  1793.                         as_fatal("Bad size for expression %d",opP->con1->e_siz);
  1794.                     }
  1795.                 } else if(subs(opP->con1)) {
  1796.                         /* We can't relax it */
  1797.                     the_ins.opcode[the_ins.numo-1]|=0xff;
  1798.                     add_fix('l',opP->con1,1);
  1799.                     addword(0);
  1800.                     addword(0);
  1801.                 } else if(adds(opP->con1)) {
  1802.                     if (flagseen['m'] && 
  1803.                         (the_ins.opcode[0] >= 0x6200) &&
  1804.                         (the_ins.opcode[0] <= 0x6f00)) {
  1805.                       add_frag(adds(opP->con1),offs(opP->con1),TAB(BCC68000,SZ_UNDEF));
  1806.                     } else {
  1807.                         add_frag(adds(opP->con1),offs(opP->con1),TAB(BRANCH,SZ_UNDEF));
  1808.                     }
  1809.                 } else {
  1810.                     /* JF:  This is the WRONG thing to do
  1811.                     add_frag((symbolS *)0,offs(opP->con1),TAB(BRANCH,BYTE)); */
  1812.                     the_ins.opcode[the_ins.numo-1]|=0xff;
  1813.                     offs(opP->con1)+=4;
  1814.                     add_fix('l',opP->con1,1);
  1815.                     addword(0);
  1816.                     addword(0);
  1817.                 }
  1818.                 break;
  1819.             case 'w':
  1820.                 if(isvar(opP->con1)) {
  1821.                     /* check for DBcc instruction */
  1822.                     if ((the_ins.opcode[0] & 0xf0f8) ==0x50c8) {
  1823.                         /* size varies if patch */
  1824.                         /* needed for long form */
  1825.                         add_frag(adds(opP->con1),offs(opP->con1),TAB(DBCC,SZ_UNDEF));
  1826.                         break;
  1827.                     }
  1828.  
  1829.                         /* Don't ask! */
  1830.                     offs(opP->con1) += 2;
  1831.                     add_fix('w',opP->con1,1);
  1832.                 }
  1833.                 addword(0);
  1834.                 break;
  1835.             case 'c':
  1836.                 if(opP->con1->e_siz) {
  1837.                     switch(opP->con1->e_siz) {
  1838.                     case 2:
  1839.                         add_fix('w',opP->con1,1)
  1840.                         addword(0);
  1841.                         break;
  1842.                     case 3:
  1843.                         the_ins.opcode[the_ins.numo-1]|=0x40;
  1844.                         add_fix('l',opP->con1,1);
  1845.                         addword(0);
  1846.                         addword(0);
  1847.                         break;
  1848.                     default:
  1849.                         as_bad("Bad size for offset, must be word or long");
  1850.                         break;
  1851.                     }
  1852.                 } else if(subs(opP->con1)) {
  1853.                     add_fix('l',opP->con1,1);
  1854.                     add_frag((symbolS *)0,(long)0,TAB(FBRANCH,LONG));
  1855.                 } else if(adds(opP->con1)) {
  1856.                     add_frag(adds(opP->con1),offs(opP->con1),TAB(FBRANCH,SZ_UNDEF));
  1857.                 } else {
  1858.                     /* add_frag((symbolS *)0,offs(opP->con1),TAB(FBRANCH,SHORT)); */
  1859.                     the_ins.opcode[the_ins.numo-1]|=0x40;
  1860.                     add_fix('l',opP->con1,1);
  1861.                     addword(0);
  1862.                     addword(4);
  1863.                 }
  1864.                 break;
  1865.             default:
  1866.                 as_fatal("Internal error:  operand type B%c unknown",s[1]);
  1867.             }
  1868.             break;
  1869.  
  1870.         case 'C':        /* Ignore it */
  1871.             break;
  1872.  
  1873.         case 'd':        /* JF this is a kludge */
  1874.             if(opP->mode==AOFF) {
  1875.                 install_operand('s',opP->reg-ADDR);
  1876.             } else {
  1877.                 char *tmpP;
  1878.  
  1879.                 tmpP=opP->con1->e_end-2;
  1880.                 opP->con1->e_beg++;
  1881.                 opP->con1->e_end-=4;    /* point to the , */
  1882.                 baseo=m68k_reg_parse(&tmpP);
  1883.                 if(baseo<ADDR+0 || baseo>ADDR+7) {
  1884.                     as_bad("Unknown address reg, using A0");
  1885.                     baseo=0;
  1886.                 } else baseo-=ADDR;
  1887.                 install_operand('s',baseo);
  1888.             }
  1889.             tmpreg=get_num(opP->con1,80);
  1890.             if(!issword(tmpreg)) {
  1891.                 as_warn("Expression out of range, using 0");
  1892.                 tmpreg=0;
  1893.             }
  1894.             addword(tmpreg);
  1895.             break;
  1896.  
  1897.         case 'D':
  1898.             install_operand(s[1],opP->reg-DATA);
  1899.             break;
  1900.  
  1901.         case 'F':
  1902.             install_operand(s[1],opP->reg-FPREG);
  1903.             break;
  1904.  
  1905.         case 'I':
  1906.             tmpreg=1+opP->reg-COPNUM;
  1907.             if(tmpreg==8)
  1908.                 tmpreg=0;
  1909.             install_operand(s[1],tmpreg);
  1910.             break;
  1911.  
  1912.         case 'J':        /* JF foo */
  1913.             switch(opP->reg) {
  1914.             case SFC:
  1915.                 tmpreg=0;
  1916.                 break;
  1917.             case DFC:
  1918.                 tmpreg=0x001;
  1919.                 break;
  1920.             case CACR:
  1921.                 tmpreg=0x002;
  1922.                 break;
  1923.             case USP:
  1924.                 tmpreg=0x800;
  1925.                 break;
  1926.             case VBR:
  1927.                 tmpreg=0x801;
  1928.                 break;
  1929.             case CAAR:
  1930.                 tmpreg=0x802;
  1931.                 break;
  1932.             case MSP:
  1933.                 tmpreg=0x803;
  1934.                 break;
  1935.             case ISP:
  1936.                 tmpreg=0x804;
  1937.                 break;
  1938.             default:
  1939.                 abort();
  1940.             }
  1941.             install_operand(s[1],tmpreg);
  1942.             break;
  1943.  
  1944.         case 'k':
  1945.             tmpreg=get_num(opP->con1,55);
  1946.             install_operand(s[1],tmpreg&0x7f);
  1947.             break;
  1948.  
  1949.         case 'l':
  1950.             tmpreg=opP->reg;
  1951.             if(s[1]=='w') {
  1952.                 if(tmpreg&0x7FF0000)
  1953.                     as_bad("Floating point register in register list");
  1954.                 insop(reverse_16_bits(tmpreg));
  1955.             } else {
  1956.                 if(tmpreg&0x700FFFF)
  1957.                     as_bad("Wrong register in floating-point reglist");
  1958.                 install_operand(s[1],reverse_8_bits(tmpreg>>16));
  1959.             }
  1960.             break;
  1961.  
  1962.         case 'L':
  1963.             tmpreg=opP->reg;
  1964.             if(s[1]=='w') {
  1965.                 if(tmpreg&0x7FF0000)
  1966.                     as_bad("Floating point register in register list");
  1967.                 insop(tmpreg);
  1968.             } else if(s[1]=='8') {
  1969.                 if(tmpreg&0x0FFFFFF)
  1970.                     as_bad("incorrect register in reglist");
  1971.                 install_operand(s[1],tmpreg>>24);
  1972.             } else {
  1973.                 if(tmpreg&0x700FFFF)
  1974.                     as_bad("wrong register in floating-point reglist");
  1975.                 else
  1976.                     install_operand(s[1],tmpreg>>16);
  1977.             }
  1978.             break;
  1979.  
  1980.         case 'M':
  1981.             install_operand(s[1],get_num(opP->con1,60));
  1982.             break;
  1983.  
  1984.         case 'O':
  1985.             tmpreg= (opP->mode==DREG)
  1986.                 ? 0x20+opP->reg-DATA
  1987.                 : (get_num(opP->con1,40)&0x1F);
  1988.             install_operand(s[1],tmpreg);
  1989.             break;
  1990.  
  1991.         case 'Q':
  1992.             if (s[1]!='s') {
  1993.                 tmpreg=get_num(opP->con1,10);
  1994.                   if(tmpreg==8)
  1995.                     tmpreg=0;
  1996.             }
  1997.             else {
  1998.                 tmpreg=get_num(opP->con1,20);
  1999.                   if(tmpreg==8)
  2000.                     tmpreg=0;
  2001.             }
  2002.             install_operand(s[1],tmpreg);
  2003.             break;
  2004.  
  2005.         case 'R':
  2006.             /* This depends on the fact that ADDR registers are
  2007.                eight more than their corresponding DATA regs, so
  2008.                the result will have the ADDR_REG bit set */
  2009.             install_operand(s[1],opP->reg-DATA);
  2010.             break;
  2011.  
  2012.         case 's':
  2013.             if(opP->reg==FPI) tmpreg=0x1;
  2014.             else if(opP->reg==FPS) tmpreg=0x2;
  2015.             else if(opP->reg==FPC) tmpreg=0x4;
  2016.             else abort();
  2017.             install_operand(s[1],tmpreg);
  2018.             break;
  2019.  
  2020.         case 'S':    /* Ignore it */
  2021.             break;
  2022.  
  2023.         case 'T':
  2024.             install_operand(s[1],get_num(opP->con1,30));
  2025.             break;
  2026.  
  2027.         case 'U':    /* Ignore it */
  2028.             break;
  2029.  
  2030. #ifdef m68851
  2031.             /* JF: These are out of order, I fear. */
  2032.         case 'f':
  2033.             switch (opP->reg) {
  2034.             case SFC:
  2035.                 tmpreg=0;
  2036.                 break;
  2037.             case DFC:
  2038.                 tmpreg=1;
  2039.                 break;
  2040.             default:
  2041.                 abort();
  2042.             }
  2043.             install_operand(s[1],tmpreg);
  2044.             break;
  2045.  
  2046.         case 'P':
  2047.             switch(opP->reg) {
  2048.             case TC:
  2049.                 tmpreg=0;
  2050.                 break;
  2051.             case CAL:
  2052.                 tmpreg=4;
  2053.                 break;
  2054.             case VAL:
  2055.                 tmpreg=5;
  2056.                 break;
  2057.             case SCC:
  2058.                 tmpreg=6;
  2059.                 break;
  2060.             case AC:
  2061.                 tmpreg=7;
  2062.                 break;
  2063.             default:
  2064.                 abort();
  2065.             }
  2066.             install_operand(s[1],tmpreg);
  2067.             break;
  2068.  
  2069.         case 'V':
  2070.             if (opP->reg == VAL)
  2071.                 break;
  2072.             abort();
  2073.  
  2074.         case 'W':
  2075.             switch(opP->reg) {
  2076.  
  2077.             case DRP:
  2078.                 tmpreg=1;
  2079.                 break;
  2080.             case SRP:
  2081.                 tmpreg=2;
  2082.                 break;
  2083.             case CRP:
  2084.                 tmpreg=3;
  2085.                 break;
  2086.             default:
  2087.                 abort();
  2088.             }
  2089.             install_operand(s[1],tmpreg);
  2090.             break;
  2091.  
  2092.         case 'X':
  2093.             switch (opP->reg) {
  2094.             case BAD: case BAD+1: case BAD+2: case BAD+3:
  2095.             case BAD+4: case BAD+5: case BAD+6: case BAD+7:
  2096.                 tmpreg = (4 << 10) | ((opP->reg - BAD) << 2);
  2097.                 break;
  2098.  
  2099.             case BAC: case BAC+1: case BAC+2: case BAC+3:
  2100.             case BAC+4: case BAC+5: case BAC+6: case BAC+7:
  2101.                 tmpreg = (5 << 10) | ((opP->reg - BAC) << 2);
  2102.                 break;
  2103.  
  2104.             default:
  2105.                 abort();
  2106.             }
  2107.             install_operand(s[1], tmpreg);
  2108.             break;
  2109.         case 'Y':
  2110.             if (opP->reg == PSR)
  2111.                 break;
  2112.             abort();
  2113.  
  2114.         case 'Z':
  2115.             if (opP->reg == PCSR)
  2116.                 break;
  2117.             abort();
  2118. #endif /* m68851 */
  2119.         default:
  2120.             as_fatal("Internal error:  Operand type %c unknown",s[0]);
  2121.         }
  2122.     }
  2123.     /* By the time whe get here (FINALLY) the_ins contains the complete
  2124.        instruction, ready to be emitted. . . */
  2125. }
  2126.  
  2127. int
  2128. get_regs(i,str,opP)
  2129. struct m68k_op *opP;
  2130. char *str;
  2131. {
  2132.     /*                 26, 25, 24, 23-16,  15-8, 0-7 */
  2133.     /* Low order 24 bits encoded fpc,fps,fpi,fp7-fp0,a7-a0,d7-d0 */
  2134.     unsigned long int cur_regs = 0;
  2135.     int    reg1,
  2136.         reg2;
  2137.  
  2138. #define ADD_REG(x)    {     if(x==FPI) cur_regs|=(1<<24);\
  2139.              else if(x==FPS) cur_regs|=(1<<25);\
  2140.              else if(x==FPC) cur_regs|=(1<<26);\
  2141.              else cur_regs|=(1<<(x-1));  }
  2142.  
  2143.     reg1=i;
  2144.     for(;;) {
  2145.         if(*str=='/') {
  2146.             ADD_REG(reg1);
  2147.             str++;
  2148.         } else if(*str=='-') {
  2149.             str++;
  2150.             reg2=m68k_reg_parse(&str);
  2151.             if(reg2<DATA || reg2>=FPREG+8 || reg1==FPI || reg1==FPS || reg1==FPC) {
  2152.                 opP->error="unknown register in register list";
  2153.                 return FAIL;
  2154.             }
  2155.             while(reg1<=reg2) {
  2156.                 ADD_REG(reg1);
  2157.                 reg1++;
  2158.             }
  2159.             if(*str=='\0')
  2160.                 break;
  2161.         } else if(*str=='\0') {
  2162.             ADD_REG(reg1);
  2163.             break;
  2164.         } else {
  2165.             opP->error="unknow character in register list";
  2166.             return FAIL;
  2167.         }
  2168. /* DJA -- Bug Fix.  Did't handle d1-d2/a1 until the following instruction was added */
  2169.         if (*str=='/')
  2170.           str ++;
  2171.         reg1=m68k_reg_parse(&str);
  2172.         if((reg1<DATA || reg1>=FPREG+8) && !(reg1==FPI || reg1==FPS || reg1==FPC)) {
  2173.             opP->error="unknown register in register list";
  2174.             return FAIL;
  2175.         }
  2176.     }
  2177.     opP->reg=cur_regs;
  2178.     return OK;
  2179. }
  2180.  
  2181. int
  2182. reverse_16_bits(in)
  2183. int in;
  2184. {
  2185.     int out=0;
  2186.     int n;
  2187.  
  2188.     static int mask[16] = {
  2189. 0x0001,0x0002,0x0004,0x0008,0x0010,0x0020,0x0040,0x0080,
  2190. 0x0100,0x0200,0x0400,0x0800,0x1000,0x2000,0x4000,0x8000
  2191.     };
  2192.     for(n=0;n<16;n++) {
  2193.         if(in&mask[n])
  2194.             out|=mask[15-n];
  2195.     }
  2196.     return out;
  2197. }
  2198.  
  2199. int
  2200. reverse_8_bits(in)
  2201. int in;
  2202. {
  2203.     int out=0;
  2204.     int n;
  2205.  
  2206.     static int mask[8] = {
  2207. 0x0001,0x0002,0x0004,0x0008,0x0010,0x0020,0x0040,0x0080,
  2208.     };
  2209.  
  2210.     for(n=0;n<8;n++) {
  2211.         if(in&mask[n])
  2212.             out|=mask[7-n];
  2213.     }
  2214.     return out;
  2215. }
  2216.  
  2217. void
  2218. install_operand(mode,val)
  2219. int mode;
  2220. int val;
  2221. {
  2222.     switch(mode) {
  2223.     case 's':
  2224.         the_ins.opcode[0]|=val & 0xFF;    /* JF FF is for M kludge */
  2225.         break;
  2226.     case 'd':
  2227.         the_ins.opcode[0]|=val<<9;
  2228.         break;
  2229.     case '1':
  2230.         the_ins.opcode[1]|=val<<12;
  2231.         break;
  2232.     case '2':
  2233.         the_ins.opcode[1]|=val<<6;
  2234.         break;
  2235.     case '3':
  2236.         the_ins.opcode[1]|=val;
  2237.         break;
  2238.     case '4':
  2239.         the_ins.opcode[2]|=val<<12;
  2240.         break;
  2241.     case '5':
  2242.         the_ins.opcode[2]|=val<<6;
  2243.         break;
  2244.     case '6':
  2245.             /* DANGER!  This is a hack to force cas2l and cas2w cmds
  2246.                to be three words long! */
  2247.         the_ins.numo++;
  2248.         the_ins.opcode[2]|=val;
  2249.         break;
  2250.     case '7':
  2251.         the_ins.opcode[1]|=val<<7;
  2252.         break;
  2253.     case '8':
  2254.         the_ins.opcode[1]|=val<<10;
  2255.         break;
  2256. #ifdef m68851
  2257.     case '9':
  2258.         the_ins.opcode[1]|=val<<5;
  2259.         break;
  2260. #endif
  2261.  
  2262.     case 't':
  2263.         the_ins.opcode[1]|=(val<<10)|(val<<7);
  2264.         break;
  2265.     case 'D':
  2266.         the_ins.opcode[1]|=(val<<12)|val;
  2267.         break;
  2268.     case 'g':
  2269.         the_ins.opcode[0]|=val=0xff;
  2270.         break;
  2271.     case 'i':
  2272.         the_ins.opcode[0]|=val<<9;
  2273.         break;
  2274.     case 'C':
  2275.         the_ins.opcode[1]|=val;
  2276.         break;
  2277.     case 'j':
  2278.         the_ins.opcode[1]|=val;
  2279.         the_ins.numo++;        /* What a hack */
  2280.         break;
  2281.     case 'k':
  2282.         the_ins.opcode[1]|=val<<4;
  2283.         break;
  2284.     case 'b':
  2285.     case 'w':
  2286.     case 'l':
  2287.         break;
  2288.     case 'c':
  2289.     default:
  2290.         abort();
  2291.     }
  2292. }
  2293.  
  2294. void
  2295. install_gen_operand(mode,val)
  2296. int mode;
  2297. int val;
  2298. {
  2299.     switch(mode) {
  2300.     case 's':
  2301.         the_ins.opcode[0]|=val;
  2302.         break;
  2303.     case 'd':
  2304.             /* This is a kludge!!! */
  2305.         the_ins.opcode[0]|=(val&0x07)<<9|(val&0x38)<<3;
  2306.         break;
  2307.     case 'b':
  2308.     case 'w':
  2309.     case 'l':
  2310.     case 'f':
  2311.     case 'F':
  2312.     case 'x':
  2313.     case 'p':
  2314.         the_ins.opcode[0]|=val;
  2315.         break;
  2316.         /* more stuff goes here */
  2317.     default:
  2318.         abort();
  2319.     }
  2320. }
  2321.  
  2322. char *
  2323. crack_operand(str,opP)
  2324. register char *str;
  2325. register struct m68k_op *opP;
  2326. {
  2327.     register int parens;
  2328.     register int c;
  2329.     register char *beg_str;
  2330.  
  2331.     if(!str) {
  2332.         return str;
  2333.     }
  2334.     beg_str=str;
  2335.     for(parens=0;*str && (parens>0 || notend(str));str++) {
  2336.         if(*str=='(') parens++;
  2337.         else if(*str==')') {
  2338.             if(!parens) {        /* ERROR */
  2339.                 opP->error="Extra )";
  2340.                 return str;
  2341.             }
  2342.             --parens;
  2343.         }
  2344.     }
  2345.     if(!*str && parens) {        /* ERROR */
  2346.         opP->error="Missing )";
  2347.         return str;
  2348.     }
  2349.     c= *str;
  2350.     *str='\0';
  2351.     if(m68k_ip_op(beg_str,opP)==FAIL) {
  2352.         *str=c;
  2353.         return str;
  2354.     }
  2355.     *str=c;
  2356.     if(c=='}')
  2357.         c= *++str;        /* JF bitfield hack */
  2358.     if(c) {
  2359.         c= *++str;
  2360.         if(!c)
  2361.             as_bad("Missing operand");
  2362.     }
  2363.     return str;
  2364. }
  2365.  
  2366. /* See the comment up above where the #define notend(... is */
  2367. #if 0
  2368. notend(s)
  2369. char *s;
  2370. {
  2371.     if(*s==',') return 0;
  2372.     if(*s=='{' || *s=='}')
  2373.         return 0;
  2374.     if(*s!=':') return 1;
  2375.         /* This kludge here is for the division cmd, which is a kludge */
  2376.     if(index("aAdD#",s[1])) return 0;
  2377.     return 1;
  2378. }
  2379. #endif
  2380.  
  2381. /* This is the guts of the machine-dependent assembler.  STR points to a
  2382.    machine dependent instruction.  This funciton is supposed to emit
  2383.    the frags/bytes it assembles to.
  2384.  */
  2385. void
  2386. md_assemble(str)
  2387. char *str;
  2388. {
  2389.     char *er;
  2390.     short    *fromP;
  2391.     char    *toP;
  2392.     int    m,n;
  2393.     char    *to_beg_P;
  2394.     int    shorts_this_frag;
  2395.  
  2396.     bzero((char *)(&the_ins),sizeof(the_ins));    /* JF for paranoia sake */
  2397.     m68_ip(str);
  2398.     er=the_ins.error;
  2399.     if(!er) {
  2400.         for(n=the_ins.numargs;n;--n)
  2401.             if(the_ins.operands[n].error) {
  2402.                 er=the_ins.operands[n].error;
  2403.                 break;
  2404.             }
  2405.     }
  2406.     if(er) {
  2407.         as_bad("\"%s\" -- Statement '%s' ignored",er,str);
  2408.         return;
  2409.     }
  2410.  
  2411.     if(the_ins.nfrag==0) {    /* No frag hacking involved; just put it out */
  2412.         toP=frag_more(2*the_ins.numo);
  2413.         fromP= &the_ins.opcode[0];
  2414.         for(m=the_ins.numo;m;--m) {
  2415.             md_number_to_chars(toP,(long)(*fromP),2);
  2416.             toP+=2;
  2417.             fromP++;
  2418.         }
  2419.             /* put out symbol-dependent info */
  2420.         for(m=0;m<the_ins.nrel;m++) {
  2421.             switch(the_ins.reloc[m].wid) {
  2422.             case 'B':
  2423.                 n=1;
  2424.                 break;
  2425.             case 'b':
  2426.                 n=1;
  2427.                 break;
  2428.             case '3':
  2429.                 n=2;
  2430.                 break;
  2431.             case 'w':
  2432.                 n=2;
  2433.                 break;
  2434.             case 'l':
  2435.                 n=4;
  2436.                 break;
  2437.             default:
  2438.                 as_fatal("Don't know how to figure width of %c in md_assemble()",the_ins.reloc[m].wid);
  2439.             }
  2440.  
  2441.             fix_new(frag_now,
  2442.                 (toP-frag_now->fr_literal)-the_ins.numo*2+the_ins.reloc[m].n,
  2443.                 n,
  2444.                 the_ins.reloc[m].add,
  2445.                 the_ins.reloc[m].sub,
  2446.                 the_ins.reloc[m].off,
  2447.                 the_ins.reloc[m].pcrel);
  2448.         }
  2449.         return;
  2450.     }
  2451.  
  2452.         /* There's some frag hacking */
  2453.     for(n=0,fromP= &the_ins.opcode[0];n<the_ins.nfrag;n++) {
  2454.         int wid;
  2455.  
  2456.         if(n==0) wid=2*the_ins.fragb[n].fragoff;
  2457.         else wid=2*(the_ins.numo-the_ins.fragb[n-1].fragoff);
  2458.         toP=frag_more(wid);
  2459.         to_beg_P=toP;
  2460.         shorts_this_frag=0;
  2461.         for(m=wid/2;m;--m) {
  2462.             md_number_to_chars(toP,(long)(*fromP),2);
  2463.             toP+=2;
  2464.             fromP++;
  2465.             shorts_this_frag++;
  2466.         }
  2467.         for(m=0;m<the_ins.nrel;m++) {
  2468.             if((the_ins.reloc[m].n)>= 2*shorts_this_frag /* 2*the_ins.fragb[n].fragoff */) {
  2469.                 the_ins.reloc[m].n-= 2*shorts_this_frag /* 2*the_ins.fragb[n].fragoff */;
  2470.                 break;
  2471.             }
  2472.             wid=the_ins.reloc[m].wid;
  2473.             if(wid==0)
  2474.                 continue;
  2475.             the_ins.reloc[m].wid=0;
  2476.             wid = (wid=='b') ? 1 : (wid=='w') ? 2 : (wid=='l') ? 4 : 4000;
  2477.  
  2478.             fix_new(frag_now,
  2479.                 (toP-frag_now->fr_literal)-the_ins.numo*2+the_ins.reloc[m].n,
  2480.                 wid,
  2481.                 the_ins.reloc[m].add,
  2482.                 the_ins.reloc[m].sub,
  2483.                 the_ins.reloc[m].off,
  2484.                 the_ins.reloc[m].pcrel);
  2485.         }
  2486.         know(the_ins.fragb[n].fadd);
  2487.         (void)frag_var(rs_machine_dependent,10,0,(relax_substateT)(the_ins.fragb[n].fragty),
  2488.  the_ins.fragb[n].fadd,the_ins.fragb[n].foff,to_beg_P);
  2489.     }
  2490.     n=(the_ins.numo-the_ins.fragb[n-1].fragoff);
  2491.     shorts_this_frag=0;
  2492.     if(n) {
  2493.         toP=frag_more(n*sizeof(short));
  2494.         while(n--) {
  2495.             md_number_to_chars(toP,(long)(*fromP),2);
  2496.             toP+=2;
  2497.             fromP++;
  2498.             shorts_this_frag++;
  2499.         }
  2500.     }
  2501.     for(m=0;m<the_ins.nrel;m++) {
  2502.         int wid;
  2503.  
  2504.         wid=the_ins.reloc[m].wid;
  2505.         if(wid==0)
  2506.             continue;
  2507.         the_ins.reloc[m].wid=0;
  2508.         wid = (wid=='b') ? 1 : (wid=='w') ? 2 : (wid=='l') ? 4 : 4000;
  2509.  
  2510.         fix_new(frag_now,
  2511.             (the_ins.reloc[m].n + toP-frag_now->fr_literal)-/* the_ins.numo */ shorts_this_frag*2,
  2512.             wid,
  2513.             the_ins.reloc[m].add,
  2514.             the_ins.reloc[m].sub,
  2515.             the_ins.reloc[m].off,
  2516.             the_ins.reloc[m].pcrel);
  2517.     }
  2518. }
  2519.  
  2520. /* This function is called once, at assembler startup time.  This should
  2521.    set up all the tables, etc that the MD part of the assembler needs
  2522.  */
  2523. void
  2524. md_begin()
  2525. {
  2526. /*
  2527.  * md_begin -- set up hash tables with 68000 instructions.
  2528.  * similar to what the vax assembler does.  ---phr
  2529.  */
  2530.     /* RMS claims the thing to do is take the m68k-opcode.h table, and make
  2531.        a copy of it at runtime, adding in the information we want but isn't
  2532.        there.  I think it'd be better to have an awk script hack the table
  2533.        at compile time.  Or even just xstr the table and use it as-is.  But
  2534.        my lord ghod hath spoken, so we do it this way.  Excuse the ugly var
  2535.        names.  */
  2536.  
  2537.     register struct m68k_opcode *ins;
  2538.     register struct m68_incant *hack,
  2539.         *slak;
  2540.     register char *retval = 0;        /* empty string, or error msg text */
  2541.     register int i;
  2542.     register char c;
  2543.  
  2544.     if ((op_hash = hash_new()) == NULL)
  2545.         as_fatal("Virtual memory exhausted");
  2546.  
  2547.     obstack_begin(&robyn,4000);
  2548.     for (ins = m68k_opcodes; ins < endop; ins++) {
  2549.         hack=slak=(struct m68_incant *)obstack_alloc(&robyn,sizeof(struct m68_incant));
  2550.         do {
  2551.             slak->m_operands=ins->args;
  2552.             slak->m_opnum=strlen(slak->m_operands)/2;
  2553.             slak->m_opcode=ins->opcode;
  2554.                 /* This is kludgey */
  2555.             slak->m_codenum=((ins->match)&0xffffL) ? 2 : 1;
  2556.             if((ins+1)!=endop && !strcmp(ins->name,(ins+1)->name)) {
  2557.                 slak->m_next=(struct m68_incant *)
  2558. obstack_alloc(&robyn,sizeof(struct m68_incant));
  2559.                 ins++;
  2560.             } else
  2561.                 slak->m_next=0;
  2562.             slak=slak->m_next;
  2563.         } while(slak);
  2564.  
  2565.         retval = hash_insert (op_hash, ins->name,(char *)hack);
  2566.             /* Didn't his mommy tell him about null pointers? */
  2567.         if(retval && *retval)
  2568.             as_fatal("Internal Error:  Can't hash %s: %s",ins->name,retval);
  2569.     }
  2570.  
  2571.     for (i = 0; i < sizeof(mklower_table) ; i++)
  2572.         mklower_table[i] = (isupper(c = (char) i)) ? tolower(c) : c;
  2573.  
  2574.     for (i = 0 ; i < sizeof(notend_table) ; i++) {
  2575.         notend_table[i] = 0;
  2576.         alt_notend_table[i] = 0;
  2577.     }
  2578.     notend_table[','] = 1;
  2579.     notend_table['{'] = 1;
  2580.     notend_table['}'] = 1;
  2581.     alt_notend_table['a'] = 1;
  2582.     alt_notend_table['A'] = 1;
  2583.     alt_notend_table['d'] = 1;
  2584.     alt_notend_table['D'] = 1;
  2585.     alt_notend_table['#'] = 1;
  2586.     alt_notend_table['f'] = 1;
  2587.     alt_notend_table['F'] = 1;
  2588. #ifdef REGISTER_PREFIX
  2589.     alt_notend_table[REGISTER_PREFIX] = 1;
  2590. #endif
  2591. }
  2592.  
  2593. #if 0
  2594. #define notend(s) ((*s == ',' || *s == '}' || *s == '{' \
  2595.                    || (*s == ':' && index("aAdD#", s[1]))) \
  2596.                ? 0 : 1)
  2597. #endif
  2598.  
  2599. /* This funciton is called once, before the assembler exits.  It is
  2600.    supposed to do any final cleanup for this part of the assembler.
  2601.  */
  2602. void
  2603. md_end()
  2604. {
  2605. }
  2606.  
  2607. /* Equal to MAX_PRECISION in atof-ieee.c */
  2608. #define MAX_LITTLENUMS 6
  2609.  
  2610. /* Turn a string in input_line_pointer into a floating point constant of type
  2611.    type, and store the appropriate bytes in *litP.  The number of LITTLENUMS
  2612.    emitted is stored in *sizeP .  An error message is returned, or NULL on OK.
  2613.  */
  2614. char *
  2615. md_atof(type,litP,sizeP)
  2616. char type;
  2617. char *litP;
  2618. int *sizeP;
  2619. {
  2620.     int    prec;
  2621.     LITTLENUM_TYPE words[MAX_LITTLENUMS];
  2622.     LITTLENUM_TYPE *wordP;
  2623.     char    *t;
  2624.     char    *atof_ieee();
  2625.  
  2626.     switch(type) {
  2627.     case 'f':
  2628.     case 'F':
  2629.     case 's':
  2630.     case 'S':
  2631.         prec = 2;
  2632.         break;
  2633.  
  2634.     case 'd':
  2635.     case 'D':
  2636.     case 'r':
  2637.     case 'R':
  2638.         prec = 4;
  2639.         break;
  2640.  
  2641.     case 'x':
  2642.     case 'X':
  2643.         prec = 6;
  2644.         break;
  2645.  
  2646.     case 'p':
  2647.     case 'P':
  2648.         prec = 6;
  2649.         break;
  2650.  
  2651.     default:
  2652.         *sizeP=0;
  2653.         return "Bad call to MD_ATOF()";
  2654.     }
  2655.     t=atof_ieee(input_line_pointer,type,words);
  2656.     if(t)
  2657.         input_line_pointer=t;
  2658.  
  2659.     *sizeP=prec * sizeof(LITTLENUM_TYPE);
  2660.     for(wordP=words;prec--;) {
  2661.         md_number_to_chars(litP,(long)(*wordP++),sizeof(LITTLENUM_TYPE));
  2662.         litP+=sizeof(LITTLENUM_TYPE);
  2663.     }
  2664.     return "";    /* Someone should teach Dean about null pointers */
  2665. }
  2666.  
  2667. /* Turn an integer of n bytes (in val) into a stream of bytes appropriate
  2668.    for use in the a.out file, and stores them in the array pointed to by buf.
  2669.    This knows about the endian-ness of the target machine and does
  2670.    THE RIGHT THING, whatever it is.  Possible values for n are 1 (byte)
  2671.    2 (short) and 4 (long)  Floating numbers are put out as a series of
  2672.    LITTLENUMS (shorts, here at least)
  2673.  */
  2674. void
  2675. md_number_to_chars(buf,val,n)
  2676. char    *buf;
  2677. long    val;
  2678. int n;
  2679. {
  2680.     switch(n) {
  2681.     case 1:
  2682.         *buf++=val;
  2683.         break;
  2684.     case 2:
  2685.         *buf++=(val>>8);
  2686.         *buf++=val;
  2687.         break;
  2688.     case 4:
  2689.         *buf++=(val>>24);
  2690.         *buf++=(val>>16);
  2691.         *buf++=(val>>8);
  2692.         *buf++=val;
  2693.         break;
  2694.     default:
  2695.         abort();
  2696.     }
  2697. }
  2698.  
  2699. void
  2700. md_number_to_imm(buf,val,n)
  2701. char *buf;
  2702. long val;
  2703. int n;
  2704. {
  2705.     switch(n) {
  2706.     case 1:
  2707.         *buf++=val;
  2708.         break;
  2709.     case 2:
  2710.         *buf++=(val>>8);
  2711.         *buf++=val;
  2712.         break;
  2713.     case 4:
  2714.         *buf++=(val>>24);
  2715.         *buf++=(val>>16);
  2716.         *buf++=(val>>8);
  2717.         *buf++=val;
  2718.         break;
  2719.     default:
  2720.         abort();
  2721.     }
  2722. }
  2723.  
  2724. void
  2725. md_number_to_disp(buf,val,n)
  2726. char    *buf;
  2727. long    val;
  2728. int n;
  2729. {
  2730.     abort();
  2731. }
  2732.  
  2733. void
  2734. md_number_to_field(buf,val,fix)
  2735. char *buf;
  2736. long val;
  2737. void *fix;
  2738. {
  2739.     abort();
  2740. }
  2741.  
  2742.  
  2743. /* *fragP has been relaxed to its final size, and now needs to have
  2744.    the bytes inside it modified to conform to the new size  There is UGLY
  2745.    MAGIC here. ..
  2746.  */
  2747. void
  2748. md_convert_frag(fragP)
  2749. register fragS *fragP;
  2750. {
  2751.   long disp;
  2752.   long ext;
  2753.  
  2754.   /* Address in gas core of the place to store the displacement.  */
  2755.   register char *buffer_address = fragP -> fr_fix + fragP -> fr_literal;
  2756.   /* Address in object code of the displacement.  */
  2757.   register int object_address = fragP -> fr_fix + fragP -> fr_address;
  2758.  
  2759.   know(fragP->fr_symbol);
  2760.  
  2761.   /* The displacement of the address, from current location.  */
  2762.   disp = (fragP->fr_symbol->sy_value + fragP->fr_offset) - object_address;
  2763.  
  2764.   switch(fragP->fr_subtype) {
  2765.   case TAB(BCC68000,BYTE):
  2766.   case TAB(BRANCH,BYTE):
  2767.     know(issbyte(disp));
  2768.     if(disp==0)
  2769.       as_bad("short branch with zero offset: use :w");
  2770.     fragP->fr_opcode[1]=disp;
  2771.     ext=0;
  2772.     break;
  2773.   case TAB(DBCC,SHORT):
  2774.     know(issword(disp));
  2775.     ext=2;
  2776.     break;
  2777.   case TAB(BCC68000,SHORT):
  2778.   case TAB(BRANCH,SHORT):
  2779.     know(issword(disp));
  2780.     fragP->fr_opcode[1]=0x00;
  2781.     ext=2;
  2782.     break;
  2783.   case TAB(BRANCH,LONG):
  2784.     if(flagseen['m']) {
  2785.       if(fragP->fr_opcode[0]==0x61) {
  2786.     fragP->fr_opcode[0]= 0x4E;
  2787.     fragP->fr_opcode[1]= 0xB9;    /* JBSR with ABSL LONG offset */
  2788.     subseg_change(SEG_TEXT, 0);
  2789.     fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0, fragP->fr_offset, 0);
  2790.     fragP->fr_fix+=4;
  2791.     ext=0;
  2792.       } else if(fragP->fr_opcode[0]==0x60) {
  2793.         fragP->fr_opcode[0]= 0x4E;
  2794.         fragP->fr_opcode[1]= 0xF9;      /* JMP  with ABSL LONG offset */
  2795.         subseg_change(SEG_TEXT, 0);
  2796.         fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0, fragP->fr_offset,0);
  2797.         fragP->fr_fix+=4;
  2798.         ext=0;
  2799.       }else {
  2800.         as_bad("Long branch offset not supported.");
  2801.       }
  2802.     } else {
  2803.       fragP->fr_opcode[1]=0xff;
  2804.       ext=4;
  2805.     }
  2806.     break;
  2807.   case TAB(BCC68000,LONG):
  2808.     /* only Bcc 68000 instructions can come here */
  2809.         /* change bcc into b!cc/jmp absl long */
  2810.     fragP->fr_opcode[0] ^= 0x01; /* invert bcc */
  2811.         fragP->fr_opcode[1] = 0x6;   /* branch offset = 6 */
  2812.  
  2813.     /* JF: these used to be fr_opcode[2,3], but they may be in a
  2814.        different frag, in which case refering to them is a no-no.
  2815.        Only fr_opcode[0,1] are guaranteed to work. */
  2816.         *buffer_address++ = 0x4e;  /* put in jmp long (0x4ef9) */ 
  2817.         *buffer_address++ = 0xf9;  
  2818.         fragP->fr_fix += 2;         /* account for jmp instruction */
  2819.         subseg_change(SEG_TEXT,0);
  2820.         fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0, 
  2821.                      fragP->fr_offset,0);
  2822.         fragP->fr_fix += 4;
  2823.         ext=0;
  2824.     break;
  2825.   case TAB(DBCC,LONG):
  2826.         /* only DBcc 68000 instructions can come here */
  2827.         /* change dbcc into dbcc/jmp absl long */
  2828.     /* JF: these used to be fr_opcode[2-7], but that's wrong */
  2829.         *buffer_address++ = 0x00;  /* branch offset = 4 */
  2830.         *buffer_address++ = 0x04;  
  2831.         *buffer_address++ = 0x60;  /* put in bra pc+6 */ 
  2832.         *buffer_address++ = 0x06;  
  2833.         *buffer_address++ = 0x4e;  /* put in jmp long (0x4ef9) */ 
  2834.         *buffer_address++ = 0xf9;  
  2835.  
  2836.         fragP->fr_fix += 6;         /* account for bra/jmp instructions */
  2837.         subseg_change(SEG_TEXT,0);
  2838.         fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0, 
  2839.                      fragP->fr_offset,0);
  2840.         fragP->fr_fix += 4;
  2841.         ext=0;
  2842.     break;
  2843.   case TAB(FBRANCH,SHORT):
  2844.     know((fragP->fr_opcode[1]&0x40)==0);
  2845.     ext=2;
  2846.     break;
  2847.   case TAB(FBRANCH,LONG):
  2848.     fragP->fr_opcode[1]|=0x40;    /* Turn on LONG bit */
  2849.     ext=4;
  2850.     break;
  2851.   case TAB(PCREL,SHORT):
  2852.     ext=2;
  2853.     break;
  2854.   case TAB(PCREL,LONG):
  2855.     /* The thing to do here is force it to ABSOLUTE LONG, since
  2856.        PCREL is really trying to shorten an ABSOLUTE address anyway */
  2857.     /* JF FOO This code has not been tested */
  2858.     subseg_change(SEG_TEXT,0);
  2859.     fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0, fragP->fr_offset, 0);
  2860.     if((fragP->fr_opcode[1] & 0x3F) != 0x3A)
  2861.       as_bad("Internal error (long PC-relative operand) for insn 0x%04lx at 0x%lx",
  2862.             fragP->fr_opcode[0],fragP->fr_address);
  2863.     fragP->fr_opcode[1]&= ~0x3F;
  2864.     fragP->fr_opcode[1]|=0x39;    /* Mode 7.1 */
  2865.     fragP->fr_fix+=4;
  2866.     /* md_number_to_chars(buffer_address,
  2867.                (long)(fragP->fr_symbol->sy_value + fragP->fr_offset),
  2868.                4); */
  2869.     ext=0;
  2870.     break;
  2871.   case TAB(PCLEA,SHORT):
  2872.     subseg_change(SEG_TEXT,0);
  2873.     fix_new(fragP,(int)(fragP->fr_fix),2,fragP->fr_symbol,(symbolS *)0,fragP->fr_offset,1);
  2874.     fragP->fr_opcode[1] &= ~0x3F;
  2875.     fragP->fr_opcode[1] |= 0x3A;
  2876.     ext=2;
  2877.     break;
  2878.   case TAB(PCLEA,LONG):
  2879.     subseg_change(SEG_TEXT,0);
  2880.     fix_new(fragP,(int)(fragP->fr_fix)+2,4,fragP->fr_symbol,(symbolS *)0,fragP->fr_offset+4,1);
  2881.     *buffer_address++ = 0x01;
  2882.     *buffer_address++ = 0x70;
  2883.     fragP->fr_fix+=2;
  2884.     /* buffer_address+=2; */
  2885.     ext=4;
  2886.     break;
  2887.  
  2888.   }
  2889.   if(ext) {
  2890.     md_number_to_chars(buffer_address,(long)disp,(int)ext);
  2891.     fragP->fr_fix+=ext;
  2892.   }
  2893. }
  2894.  
  2895. /* Force truly undefined symbols to their maximum size, and generally set up
  2896.    the frag list to be relaxed
  2897.  */
  2898. int
  2899. md_estimate_size_before_relax(fragP,segtype)
  2900. register fragS *fragP;
  2901. int segtype;
  2902. {
  2903.     int    old_fix;
  2904.     register char *buffer_address = fragP -> fr_fix + fragP -> fr_literal;
  2905.  
  2906.     old_fix=fragP->fr_fix;
  2907.  
  2908.     /* handle SZ_UNDEF first, it can be changed to BYTE or SHORT */
  2909.     switch(fragP->fr_subtype) {
  2910.     case TAB(BRANCH,SZ_UNDEF):
  2911.         if((fragP->fr_symbol->sy_type&N_TYPE)==segtype) {
  2912.             fragP->fr_subtype=TAB(TABTYPE(fragP->fr_subtype),BYTE);
  2913.             break;
  2914.         } else if(flagseen['m']) {
  2915.             if(fragP->fr_opcode[0]==0x61) {
  2916.                 if(flagseen['l']) {
  2917.                     fragP->fr_opcode[0]= 0x4E;
  2918.                     fragP->fr_opcode[1]= 0xB8;    /* JBSR with ABSL WORD offset */
  2919.                     subseg_change(SEG_TEXT, 0);
  2920.                     fix_new(fragP, fragP->fr_fix, 2, 
  2921.                         fragP->fr_symbol, 0, fragP->fr_offset, 0);
  2922.                     fragP->fr_fix+=2;
  2923.                 } else {
  2924.                     fragP->fr_opcode[0]= 0x4E;
  2925.                     fragP->fr_opcode[1]= 0xB9;    /* JBSR with ABSL LONG offset */
  2926.                     subseg_change(SEG_TEXT, 0);
  2927.                     fix_new(fragP, fragP->fr_fix, 4, 
  2928.                         fragP->fr_symbol, 0, fragP->fr_offset, 0);
  2929.                     fragP->fr_fix+=4;
  2930.                 }
  2931.                 frag_wane(fragP);
  2932.             } else if(fragP->fr_opcode[0]==0x60) {
  2933.                 if(flagseen['l']) {
  2934.                     fragP->fr_opcode[0]= 0x4E;
  2935.                     fragP->fr_opcode[1]= 0xF8;    /* JMP    with ABSL WORD offset */
  2936.                     subseg_change(SEG_TEXT, 0);
  2937.                     fix_new(fragP, fragP->fr_fix, 2, 
  2938.                         fragP->fr_symbol, 0, fragP->fr_offset, 0);
  2939.                     fragP->fr_fix+=2;
  2940.                 } else {
  2941.                     fragP->fr_opcode[0]= 0x4E;
  2942.                     fragP->fr_opcode[1]= 0xF9;    /* JMP    with ABSL LONG offset */
  2943.                     subseg_change(SEG_TEXT, 0);
  2944.                     fix_new(fragP, fragP->fr_fix, 4, 
  2945.                         fragP->fr_symbol, 0, fragP->fr_offset, 0);
  2946.                     fragP->fr_fix+=4;
  2947.                 }
  2948.                 frag_wane(fragP);
  2949.             } else {
  2950.                 as_warn("Long branch offset to extern symbol not supported.");
  2951.             }
  2952.         } else if(flagseen['l']) {    /* Symbol is still undefined.  Make it simple */
  2953.             fix_new(fragP,(int)(fragP->fr_fix),2,fragP->fr_symbol,
  2954.  (symbolS *)0,fragP->fr_offset + 2,1);
  2955.             fragP->fr_fix+=2;
  2956.             fragP->fr_opcode[1]=0x00;
  2957.             frag_wane(fragP);
  2958.         } else {
  2959.             fix_new(fragP,(int)(fragP->fr_fix),4,fragP->fr_symbol,
  2960.  (symbolS *)0,fragP->fr_offset + 4,1);
  2961.             fragP->fr_fix+=4;
  2962.             fragP->fr_opcode[1]=0xff;
  2963.             frag_wane(fragP);
  2964.             break;
  2965.         }
  2966.         break;
  2967.  
  2968.     case TAB(FBRANCH,SZ_UNDEF):
  2969.         if((fragP->fr_symbol->sy_type&N_TYPE)==segtype || flagseen['l']) {
  2970.             fragP->fr_subtype=TAB(FBRANCH,SHORT);
  2971.             fragP->fr_var+=2;
  2972.         } else {
  2973.             fragP->fr_subtype=TAB(FBRANCH,LONG);
  2974.             fragP->fr_var+=4;
  2975.         }
  2976.         break;
  2977.  
  2978.     case TAB(PCREL,SZ_UNDEF):
  2979.         if((fragP->fr_symbol->sy_type&N_TYPE)==segtype || flagseen['l']) {
  2980.             fragP->fr_subtype=TAB(PCREL,SHORT);
  2981.             fragP->fr_var+=2;
  2982.         } else {
  2983.             fragP->fr_subtype=TAB(PCREL,LONG);
  2984.             fragP->fr_var+=4;
  2985.         }
  2986.         break;
  2987.  
  2988.     case TAB(BCC68000,SZ_UNDEF):
  2989.         if((fragP->fr_symbol->sy_type&N_TYPE)==segtype) {
  2990.             fragP->fr_subtype=TAB(BCC68000,BYTE);
  2991.             break;
  2992.         }
  2993.         /* only Bcc 68000 instructions can come here */
  2994.         /* change bcc into b!cc/jmp absl long */
  2995.         fragP->fr_opcode[0] ^= 0x01; /* invert bcc */
  2996.         if(flagseen['l']) {
  2997.             fragP->fr_opcode[1] = 0x04;   /* branch offset = 6 */
  2998.             /* JF: these were fr_opcode[2,3] */
  2999.             buffer_address[0] = 0x4e;  /* put in jmp long (0x4ef9) */ 
  3000.             buffer_address[1] = 0xf8;
  3001.             fragP->fr_fix += 2;         /* account for jmp instruction */
  3002.             subseg_change(SEG_TEXT,0);
  3003.             fix_new(fragP, fragP->fr_fix, 2, fragP->fr_symbol, 0, 
  3004.                              fragP->fr_offset,0);
  3005.             fragP->fr_fix += 2;
  3006.         } else {
  3007.             fragP->fr_opcode[1] = 0x06;   /* branch offset = 6 */
  3008.             /* JF: these were fr_opcode[2,3] */
  3009.             buffer_address[2] = 0x4e;  /* put in jmp long (0x4ef9) */ 
  3010.             buffer_address[3] = 0xf9;
  3011.             fragP->fr_fix += 2;         /* account for jmp instruction */
  3012.             subseg_change(SEG_TEXT,0);
  3013.             fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0, 
  3014.                              fragP->fr_offset,0);
  3015.             fragP->fr_fix += 4;
  3016.         }
  3017.         frag_wane(fragP);
  3018.         break;
  3019.  
  3020.     case TAB(DBCC,SZ_UNDEF):
  3021.         if((fragP->fr_symbol->sy_type&N_TYPE)==segtype) {
  3022.             fragP->fr_subtype=TAB(DBCC,SHORT);
  3023.             fragP->fr_var+=2;
  3024.             break;
  3025.         }
  3026.         /* only DBcc 68000 instructions can come here */
  3027.         /* change dbcc into dbcc/jmp absl long */
  3028.         /* JF: these used to be fr_opcode[2-4], which is wrong. */
  3029.         buffer_address[0] = 0x00;  /* branch offset = 4 */
  3030.         buffer_address[1] = 0x04;  
  3031.         buffer_address[2] = 0x60;  /* put in bra pc + ... */ 
  3032.         if(flagseen['l']) {
  3033.             /* JF: these were fr_opcode[5-7] */
  3034.             buffer_address[3] = 0x04; /* plus 4 */
  3035.             buffer_address[4] = 0x4e;/* Put in Jump Word */
  3036.             buffer_address[5] = 0xf8;
  3037.             fragP->fr_fix += 6;      /* account for bra/jmp instruction */
  3038.             subseg_change(SEG_TEXT,0);
  3039.             fix_new(fragP, fragP->fr_fix, 2, fragP->fr_symbol, 0, 
  3040.                              fragP->fr_offset,0);
  3041.             fragP->fr_fix+=2;
  3042.         } else {
  3043.             /* JF: these were fr_opcode[5-7] */
  3044.             buffer_address[3] = 0x06;  /* Plus 6 */
  3045.             buffer_address[4] = 0x4e;  /* put in jmp long (0x4ef9) */ 
  3046.             buffer_address[5] = 0xf9;  
  3047.             fragP->fr_fix += 6;      /* account for bra/jmp instruction */
  3048.             subseg_change(SEG_TEXT,0);
  3049.             fix_new(fragP, fragP->fr_fix, 4, fragP->fr_symbol, 0, 
  3050.                              fragP->fr_offset,0);
  3051.             fragP->fr_fix += 4;
  3052.         }
  3053.         frag_wane(fragP);
  3054.         break;
  3055.  
  3056.     case TAB(PCLEA,SZ_UNDEF):
  3057.         if((fragP->fr_symbol->sy_type&N_TYPE)==segtype || flagseen['l']) {
  3058.             fragP->fr_subtype=TAB(PCLEA,SHORT);
  3059.             fragP->fr_var+=2;
  3060.         } else {
  3061.             fragP->fr_subtype=TAB(PCLEA,LONG);
  3062.             fragP->fr_var+=6;
  3063.         }
  3064.         break;
  3065.  
  3066.     default:
  3067.         break;
  3068.     }
  3069.  
  3070.     /* now that SZ_UNDEF are taken care of, check others */
  3071.     switch(fragP->fr_subtype) {
  3072.     case TAB(BCC68000,BYTE):
  3073.     case TAB(BRANCH,BYTE):
  3074.             /* We can't do a short jump to the next instruction,
  3075.                so we force word mode.  */
  3076.         if(fragP->fr_symbol && fragP->fr_symbol->sy_value==0 &&
  3077.  fragP->fr_symbol->sy_frag==fragP->fr_next) {
  3078.             fragP->fr_subtype=TAB(TABTYPE(fragP->fr_subtype),SHORT);
  3079.             fragP->fr_var+=2;
  3080.         }
  3081.         break;
  3082.     default:
  3083.         break;
  3084.     }
  3085.     return fragP->fr_var + fragP->fr_fix - old_fix;
  3086. }
  3087.  
  3088. /* the bit-field entries in the relocation_info struct plays hell 
  3089.    with the byte-order problems of cross-assembly.  So as a hack,
  3090.    I added this mach. dependent ri twiddler.  Ugly, but it gets
  3091.    you there. -KWK */
  3092. /* on m68k: first 4 bytes are normal unsigned long, next three bytes
  3093. are symbolnum, most sig. byte first.  Last byte is broken up with
  3094. bit 7 as pcrel, bits 6 & 5 as length, bit 4 as pcrel, and the lower
  3095. nibble as nuthin. (on Sun 3 at least) */
  3096. void
  3097. md_ri_to_chars(ri_p, ri)
  3098.      struct relocation_info *ri_p, ri;
  3099. {
  3100.   unsigned char the_bytes[8];
  3101.  
  3102.   /* this is easy */
  3103.   md_number_to_chars(the_bytes, ri.r_address, sizeof(ri.r_address));
  3104.   /* now the fun stuff */
  3105.   the_bytes[4] = (ri.r_symbolnum >> 16) & 0x0ff;
  3106.   the_bytes[5] = (ri.r_symbolnum >> 8) & 0x0ff;
  3107.   the_bytes[6] = ri.r_symbolnum & 0x0ff;
  3108.   the_bytes[7] = (((ri.r_pcrel << 7)  & 0x80) | ((ri.r_length << 5) & 0x60) | 
  3109.     ((ri.r_extern << 4)  & 0x10)); 
  3110.   /* now put it back where you found it */
  3111.   bcopy (the_bytes, (char *)ri_p, sizeof(struct relocation_info));
  3112. }
  3113.  
  3114. #ifndef WORKING_DOT_WORD
  3115. const int md_short_jump_size = 4;
  3116. const int md_long_jump_size = 6;
  3117.  
  3118. void
  3119. md_create_short_jump(ptr,from_addr,to_addr,frag,to_symbol)
  3120. char    *ptr;
  3121. long    from_addr,
  3122.     to_addr;
  3123. fragS    *frag;
  3124. symbolS    *to_symbol;
  3125. {
  3126.     long offset;
  3127.  
  3128.     offset = to_addr - (from_addr+2);
  3129.  
  3130.     md_number_to_chars(ptr  ,(long)0x6000,2);
  3131.     md_number_to_chars(ptr+2,(long)offset,2);
  3132. }
  3133.  
  3134. void
  3135. md_create_long_jump(ptr,from_addr,to_addr,frag,to_symbol)
  3136. char    *ptr;
  3137. long    from_addr,
  3138.     to_addr;
  3139. fragS    *frag;
  3140. symbolS    *to_symbol;
  3141. {
  3142.     long offset;
  3143.  
  3144.     if(flagseen['m']) {
  3145.         offset=to_addr-to_symbol->sy_value;
  3146.         md_number_to_chars(ptr  ,(long)0x4EF9,2);
  3147.         md_number_to_chars(ptr+2,(long)offset,4);
  3148.         fix_new(frag,(ptr+2)-frag->fr_literal,4,to_symbol,(symbolS *)0,(long int)0,0);
  3149.     } else {
  3150.         offset=to_addr - (from_addr+2);
  3151.         md_number_to_chars(ptr  ,(long)0x60ff,2);
  3152.         md_number_to_chars(ptr+2,(long)offset,4);
  3153.     }
  3154. }
  3155.  
  3156. #endif
  3157. /* Different values of OK tell what its OK to return.  Things that aren't OK are an error (what a shock, no?)
  3158.  
  3159.     0:  Everything is OK
  3160.     10:  Absolute 1:8    only
  3161.     20:  Absolute 0:7    only
  3162.     30:  absolute 0:15    only
  3163.     40:  Absolute 0:31    only
  3164.     50:  absolute 0:127    only
  3165.     55:  absolute -64:63    only
  3166.     60:  absolute -128:127    only
  3167.     70:  absolute 0:4095    only
  3168.     80:  No bignums
  3169.  
  3170. */
  3171. int
  3172. get_num(exp,ok)
  3173. struct m68k_exp *exp;
  3174. int ok;
  3175. {
  3176. #ifdef TEST2
  3177.     long    l = 0;
  3178.  
  3179.     if(!exp->e_beg)
  3180.         return 0;
  3181.     if(*exp->e_beg=='0') {
  3182.         if(exp->e_beg[1]=='x')
  3183.             sscanf(exp->e_beg+2,"%x",&l);
  3184.         else
  3185.             sscanf(exp->e_beg+1,"%O",&l);
  3186.         return l;
  3187.     }
  3188.     return atol(exp->e_beg);
  3189. #else
  3190.     char    *save_in;
  3191.     char    c_save;
  3192.  
  3193.     if(!exp) {
  3194.         /* Can't do anything */
  3195.         return 0;
  3196.     }
  3197.     if(!exp->e_beg || !exp->e_end) {
  3198.         seg(exp)=SEG_ABSOLUTE;
  3199.         adds(exp)=0;
  3200.         subs(exp)=0;
  3201.         offs(exp)= (ok==10) ? 1 : 0;
  3202.         as_warn("Null expression defaults to %ld",offs(exp));
  3203.         return 0;
  3204.     }
  3205.  
  3206.     exp->e_siz=0;
  3207.     if(/* ok!=80 && */exp->e_end[-1]==':' && (exp->e_end-exp->e_beg)>=2) {
  3208.         switch(exp->e_end[0]) {
  3209.         case 's':
  3210.         case 'S':
  3211.         case 'b':
  3212.         case 'B':
  3213.             exp->e_siz=1;
  3214.             break;
  3215.         case 'w':
  3216.         case 'W':
  3217.             exp->e_siz=2;
  3218.             break;
  3219.         case 'l':
  3220.         case 'L':
  3221.             exp->e_siz=3;
  3222.             break;
  3223.         default:
  3224.             as_bad("Unknown size for expression \"%c\"",exp->e_end[0]);
  3225.         }
  3226.         exp->e_end-=2;
  3227.     }
  3228.     c_save=exp->e_end[1];
  3229.     exp->e_end[1]='\0';
  3230.     save_in=input_line_pointer;
  3231.     input_line_pointer=exp->e_beg;
  3232.     switch(expression(&(exp->e_exp))) {
  3233.     case SEG_PASS1:
  3234.         seg(exp)=SEG_ABSOLUTE;
  3235.         adds(exp)=0;
  3236.         subs(exp)=0;
  3237.         offs(exp)= (ok==10) ? 1 : 0;
  3238.         as_warn("Unknown expression: '%s' defaulting to %d",exp->e_beg,offs(exp));
  3239.         break;
  3240.  
  3241.     case SEG_NONE:
  3242.         /* Do the same thing the VAX asm does */
  3243.         seg(exp)=SEG_ABSOLUTE;
  3244.         adds(exp)=0;
  3245.         subs(exp)=0;
  3246.         offs(exp)=0;
  3247.         if(ok==10) {
  3248.             as_warn("expression out of range: defaulting to 1");
  3249.             offs(exp)=1;
  3250.         }
  3251.         break;
  3252.     case SEG_ABSOLUTE:
  3253.         switch(ok) {
  3254.         case 10:
  3255.             if(offs(exp)<1 || offs(exp)>8) {
  3256.                 as_warn("expression out of range: defaulting to 1");
  3257.                 offs(exp)=1;
  3258.             }
  3259.             break;
  3260.         case 20:
  3261.             if(offs(exp)<0 || offs(exp)>7)
  3262.                 goto outrange;
  3263.             break;
  3264.         case 30:
  3265.             if(offs(exp)<0 || offs(exp)>15)
  3266.                 goto outrange;
  3267.             break;
  3268.         case 40:
  3269.             if(offs(exp)<0 || offs(exp)>32)
  3270.                 goto outrange;
  3271.             break;
  3272.         case 50:
  3273.             if(offs(exp)<0 || offs(exp)>127)
  3274.                 goto outrange;
  3275.             break;
  3276.         case 55:
  3277.             if(offs(exp)<-64 || offs(exp)>63)
  3278.                 goto outrange;
  3279.             break;
  3280.         case 60:
  3281.             if(offs(exp)<-128 || offs(exp)>127)
  3282.                 goto outrange;
  3283.             break;
  3284.         case 70:
  3285.             if(offs(exp)<0 || offs(exp)>4095) {
  3286.             outrange:
  3287.                 as_warn("expression out of range: defaulting to 0");
  3288.                 offs(exp)=0;
  3289.             }
  3290.             break;
  3291.         default:
  3292.             break;
  3293.         }
  3294.         break;
  3295.     case SEG_TEXT:
  3296.     case SEG_DATA:
  3297.     case SEG_BSS:
  3298.     case SEG_UNKNOWN:
  3299.     case SEG_DIFFERENCE:
  3300.         if(ok>=10 && ok<=70) {
  3301.             seg(exp)=SEG_ABSOLUTE;
  3302.             adds(exp)=0;
  3303.             subs(exp)=0;
  3304.             offs(exp)= (ok==10) ? 1 : 0;
  3305.             as_warn("Can't deal with expression \"%s\": defaulting to %ld",exp->e_beg,offs(exp));
  3306.         }
  3307.         break;
  3308.     case SEG_BIG:
  3309.         if(ok==80 && offs(exp)<0) {    /* HACK! Turn it into a long */
  3310.             LITTLENUM_TYPE words[6];
  3311.  
  3312.             gen_to_words(words,2,8L);/* These numbers are magic! */
  3313.             seg(exp)=SEG_ABSOLUTE;
  3314.             adds(exp)=0;
  3315.             subs(exp)=0;
  3316.             offs(exp)=words[1]|(words[0]<<16);
  3317.         } else if(ok!=0) {
  3318.             seg(exp)=SEG_ABSOLUTE;
  3319.             adds(exp)=0;
  3320.             subs(exp)=0;
  3321.             offs(exp)= (ok==10) ? 1 : 0;
  3322.             as_warn("Can't deal with expression \"%s\": defaulting to %ld",exp->e_beg,offs(exp));
  3323.         }
  3324.         break;
  3325.     default:
  3326.         abort();
  3327.     }
  3328.     if(input_line_pointer!=exp->e_end+1)
  3329.         as_bad("Ignoring junk after expression");
  3330.     exp->e_end[1]=c_save;
  3331.     input_line_pointer=save_in;
  3332.     if(exp->e_siz) {
  3333.         switch(exp->e_siz) {
  3334.         case 1:
  3335.             if(!isbyte(offs(exp)))
  3336.                 as_warn("expression doesn't fit in BYTE");
  3337.             break;
  3338.         case 2:
  3339.             if(!isword(offs(exp)))
  3340.                 as_warn("expression doesn't fit in WORD");
  3341.             break;
  3342.         }
  3343.     }
  3344.     return offs(exp);
  3345. #endif
  3346. }
  3347.  
  3348. /* These are the back-ends for the various machine dependent pseudo-ops.  */
  3349. void demand_empty_rest_of_line();    /* Hate those extra verbose names */
  3350.  
  3351. void
  3352. s_data1()
  3353. {
  3354.     subseg_new(SEG_DATA,1);
  3355.     demand_empty_rest_of_line();
  3356. }
  3357.  
  3358. void
  3359. s_data2()
  3360. {
  3361.     subseg_new(SEG_DATA,2);
  3362.     demand_empty_rest_of_line();
  3363. }
  3364.  
  3365. void
  3366. s_even()
  3367. {
  3368.     register int temp;
  3369.     register long int temp_fill;
  3370.  
  3371.     temp = 1;        /* JF should be 2? */
  3372.     temp_fill = get_absolute_expression ();
  3373.     if ( ! need_pass_2 ) /* Never make frag if expect extra pass. */
  3374.         frag_align (temp, (int)temp_fill);
  3375.     demand_empty_rest_of_line();
  3376. }
  3377.  
  3378. void
  3379. s_proc()
  3380. {
  3381.     demand_empty_rest_of_line();
  3382. }
  3383.  
  3384. /* s_space is defined in read.c .skip is simply an alias to it. */
  3385.  
  3386. int
  3387. md_parse_option(argP,cntP,vecP)
  3388. char **argP;
  3389. int *cntP;
  3390. char ***vecP;
  3391. {
  3392.     switch(**argP) {
  3393.     case 'l':    /* -l means keep external to 2 bit offset
  3394.                rather than 16 bit one */
  3395.         break;
  3396.  
  3397.     case 'm':
  3398.         /* Gas almost ignores this option! */
  3399.         (*argP)++;
  3400.         if(**argP=='c')
  3401.             (*argP)++;
  3402.         if(!strcmp(*argP,"68000"))
  3403.             flagseen['m']=2;
  3404.         else if(!strcmp(*argP,"68010")) {
  3405. #ifdef M_SUN
  3406.             omagic= 1<<16|OMAGIC;
  3407. #endif
  3408.             flagseen['m']=1;
  3409.         } else if(!strcmp(*argP,"68020"))
  3410.             flagseen['m']=0;
  3411.         else
  3412.             as_warn("Unknown -m option ignored");
  3413.         while(**argP)
  3414.             (*argP)++;
  3415.         break;
  3416.  
  3417.     default:
  3418.         return 0;
  3419.     }
  3420.     return 1;
  3421. }
  3422.  
  3423.  
  3424. #ifdef TEST2
  3425.  
  3426. /* TEST2:  Test md_assemble() */
  3427. /* Warning, this routine probably doesn't work anymore */
  3428.  
  3429. main()
  3430. {
  3431.     struct m68_it the_ins;
  3432.     char buf[120];
  3433.     char *cp;
  3434.     int    n;
  3435.  
  3436.     m68_ip_begin();
  3437.     for(;;) {
  3438.         if(!gets(buf) || !*buf)
  3439.             break;
  3440.         if(buf[0]=='|' || buf[1]=='.')
  3441.             continue;
  3442.         for(cp=buf;*cp;cp++)
  3443.             if(*cp=='\t')
  3444.                 *cp=' ';
  3445.         if(is_label(buf))
  3446.             continue;
  3447.         bzero(&the_ins,sizeof(the_ins));
  3448.         m68_ip(&the_ins,buf);
  3449.         if(the_ins.error) {
  3450.             printf("Error %s in %s\n",the_ins.error,buf);
  3451.         } else {
  3452.             printf("Opcode(%d.%s): ",the_ins.numo,the_ins.args);
  3453.             for(n=0;n<the_ins.numo;n++)
  3454.                 printf(" 0x%x",the_ins.opcode[n]&0xffff);
  3455.             printf("    ");
  3456.             print_the_insn(&the_ins.opcode[0],stdout);
  3457.             (void)putchar('\n');
  3458.         }
  3459.         for(n=0;n<strlen(the_ins.args)/2;n++) {
  3460.             if(the_ins.operands[n].error) {
  3461.                 printf("op%d Error %s in %s\n",n,the_ins.operands[n].error,buf);
  3462.                 continue;
  3463.             }
  3464.             printf("mode %d, reg %d, ",the_ins.operands[n].mode,the_ins.operands[n].reg);
  3465.             if(the_ins.operands[n].b_const)
  3466.                 printf("Constant: '%.*s', ",1+the_ins.operands[n].e_const-the_ins.operands[n].b_const,the_ins.operands[n].b_const);
  3467.             printf("ireg %d, isiz %d, imul %d, ",the_ins.operands[n].ireg,the_ins.operands[n].isiz,the_ins.operands[n].imul);
  3468.             if(the_ins.operands[n].b_iadd)
  3469.                 printf("Iadd: '%.*s',",1+the_ins.operands[n].e_iadd-the_ins.operands[n].b_iadd,the_ins.operands[n].b_iadd);
  3470.             (void)putchar('\n');
  3471.         }
  3472.     }
  3473.     m68_ip_end();
  3474.     return 0;
  3475. }
  3476.  
  3477. is_label(str)
  3478. char *str;
  3479. {
  3480.     while(*str==' ')
  3481.         str++;
  3482.     while(*str && *str!=' ')
  3483.         str++;
  3484.     if(str[-1]==':' || str[1]=='=')
  3485.         return 1;
  3486.     return 0;
  3487. }
  3488.  
  3489. #endif
  3490.  
  3491. /* Possible states for relaxation:
  3492.  
  3493. 0 0    branch offset    byte    (bra, etc)
  3494. 0 1            word
  3495. 0 2            long
  3496.  
  3497. 1 0    indexed offsets    byte    a0@(32,d4:w:1) etc
  3498. 1 1            word
  3499. 1 2            long
  3500.  
  3501. 2 0    two-offset index word-word a0@(32,d4)@(45) etc
  3502. 2 1            word-long
  3503. 2 2            long-word
  3504. 2 3            long-long
  3505.  
  3506. */
  3507.  
  3508.  
  3509.  
  3510. #ifdef DONTDEF
  3511. abort()
  3512. {
  3513.     printf("ABORT!\n");
  3514.     exit(12);
  3515. }
  3516.  
  3517. char *index(s,c)
  3518. char *s;
  3519. {
  3520.     while(*s!=c) {
  3521.         if(!*s) return 0;
  3522.         s++;
  3523.     }
  3524.     return s;
  3525. }
  3526.  
  3527. bzero(s,n)
  3528. char *s;
  3529. {
  3530.     while(n--)
  3531.         *s++=0;
  3532. }
  3533.  
  3534. print_frags()
  3535. {
  3536.     fragS *fragP;
  3537.     extern fragS *text_frag_root;
  3538.  
  3539.     for(fragP=text_frag_root;fragP;fragP=fragP->fr_next) {
  3540.         printf("addr %lu  next 0x%x  fix %ld  var %ld  symbol 0x%x  offset %ld\n",
  3541.  fragP->fr_address,fragP->fr_next,fragP->fr_fix,fragP->fr_var,fragP->fr_symbol,fragP->fr_offset);
  3542.         printf("opcode 0x%x  type %d  subtype %d\n\n",fragP->fr_opcode,fragP->fr_type,fragP->fr_subtype);
  3543.     }
  3544.     fflush(stdout);
  3545.     return 0;
  3546. }
  3547. #endif
  3548.  
  3549. #ifdef DONTDEF
  3550. /*VARARGS1*/
  3551. panic(format,args)
  3552. char *format;
  3553. {
  3554.     fputs("Internal error:",stderr);
  3555.     _doprnt(format,&args,stderr);
  3556.     (void)putc('\n',stderr);
  3557.     as_where();
  3558.     abort();
  3559. }
  3560. #endif
  3561.